添加在该行的末尾使用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找到)
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,
AWK
for file in *
do
awk '{print $0" def"}' $file >temp
mv temp "$file"
done
的Bash shell
Bash shell
for file in *
do
while read -r line
do
echo "$line def"
done < $file >temp
mv temp $file
done
这篇关于添加在该行的末尾使用sed的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文