bash 如何在shell脚本中的文件中每行末尾添加一个字符
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24518612/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to add a character to the end of each line in a file in shell script
提问by user1483747
I need a script that add a particular character to the end of each line . I am using the command
sed 's/$/ foo/' r.txt
我需要一个脚本,在每一行的末尾添加一个特定的字符。我正在使用命令
sed 's/$/ foo/' r.txt
It adds foo to end of each line in the file r.txt and displays in my terminal . What do i need to do if i want to save this existing file with this new record appended after the end of each line .
它将 foo 添加到文件 r.txt 中每一行的末尾并显示在我的终端中。如果我想保存此现有文件并在每行末尾附加此新记录,我需要做什么。
回答by David C. Rankin
To save to a new file:
要保存到新文件:
sed 's/$/ foo/' r.txt > newfile.txt
To edit in place
就地编辑
sed -i 's/$/ foo/' r.txt