在行尾添加 sed [英] Add at the end of the line with sed
本文介绍了在行尾添加 sed的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
给定一个包含多行的纯文本文档,例如:
given a plain text document with several lines like:
c48 7.587 7.39
c49 7.508 7.345983
c50 5.8 7.543
c51 8.37454546 7.34
我需要在行尾后 2 个空格处添加一些信息,因此对于每一行我都会得到:
I need to add some info 2 spaces after the end of the line, so for each line I would get:
c48 7.587 7.39 def
c49 7.508 7.345983 def
c50 5.8 7.543 def
c51 8.37454546 7.34 def
我需要为数千个文件执行此操作.我猜这可能与 sed 有关,但不知道如何操作.任何提示?你能否也给我一些关于这些案例的教程或表格的链接?
I need to do this for thousands of files. I guess this is possible to do with sed, but do not know how to. Any hint? Could you also give me some link with a tutorial or table for this cases?
谢谢
推荐答案
如果所有文件都在一个目录中
if all your files are in one directory
sed -i.bak 's/$/ def/' *.txt
递归执行(GNU find)
to do it recursive (GNU find)
find /path -type f -iname '*.txt' -exec sed -i.bak 's/$/ def/' "{}" +;
您可以在这里查看 sed 的介绍
you can see here for introduction to sed
您可以使用的其他方式,
Other ways you can use,
糟糕
for file in *
do
awk '{print $0" def"}' $file >temp
mv temp "$file"
done
Bash 外壳
for file in *
do
while read -r line
do
echo "$line def"
done < $file >temp
mv temp $file
done
这篇关于在行尾添加 sed的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文