在bash,我如何在一个文件中每一行后添加一个字符串? [英] In Bash, how do I add a string after each line in a file?

查看:441
本文介绍了在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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆