答案 0 :(得分:2)
find Root -type f -name '*.txt' -exec sed -i '1i\
line to insert
' {} +
find
命令将从Root
目录递归,查找与*.txt
匹配的文件名。然后它将执行sed
命令,该命令在文件的开头插入一行。
答案 1 :(得分:1)
以防sed -i
切换不存在。
for file in `find Root -type f -name "*.txt"`; do sed '1i\
this is the line
' $file > ${file}_new; done