在 Bash 中,如何在文件的每一行后添加一个字符串? [英] In Bash, how do I add a string after each line in a file?
本文介绍了在 Bash 中,如何在文件的每一行后添加一个字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用 bash 在文件中的每一行后添加一个字符串?是否可以使用 sed 命令完成,如果可以,如何?
How do I add a string after each line in a file using bash? Can it be done using the sed command, if so how?
推荐答案
如果您的 sed
允许通过 -i
参数进行就地
If your sed
allows in place editing via the -i
parameter:
sed -e 's/$/string after each line/' -i filename
如果没有,你必须制作一个临时文件:
If not, you have to make a temporary file:
typeset TMP_FILE=$( mktemp )
touch "${TMP_FILE}"
cp -p filename "${TMP_FILE}"
sed -e 's/$/string after each line/' "${TMP_FILE}" > filename
这篇关于在 Bash 中,如何在文件的每一行后添加一个字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文