2015-10-15 25 views

回答

2
find Root -type f -name '*.txt' -exec sed -i '1i\ 
line to insert 
' {} + 

find命令將遞歸從Root目錄,尋找符合*.txt該文件名。然後它將執行sed命令,該命令在文件的開頭插入一行。

+0

值得注意的是,這個命令需要GNU sed –

+0

感謝您的幫助barmar。 只是跟進,如果數據已經存在,是否有任何方法可以忽略寫入該文件。 – JhawarMayank

1

以防萬一sed -i開關不在那裏。

for file in `find Root -type f -name "*.txt"`; do sed '1i\ 
this is the line 
' $file > ${file}_new; done 
相關問題