如何使用 sed 将多行附加到文件中? [英] How to use sed to append multiple lines to a file?
问题描述
是的,我搜索了该网站,但我认为我没有看到任何专门解决我无法克服的(我想象的简单)问题的内容.
Yes I searched the site and I don't think I seen anything to specifically addressed my very (simple I imagine) issue that I just cannot overcome.
我正在上 Linux 课程,有人问我这个问题:
I'm taking a Linux class and I have been asked this question:
使用 sed 命令和脚本文件将这些行添加到 CD_list
文件的末尾:
Use the sed command and a script file to add these lines to the end of the
CD_list
file:
hard rock:1008:70
misc:1009:22
我反复尝试,并阅读了这一章.我想不通.
I have tried over and over, and read the chapter. I can't figure this out.
文件 CD_list 已创建,我需要将上面两行附加到它,如使用脚本文件所示.是的,难住了.
The file CD_list is created, and I need to append those two above lines to it as shown using a script file. Yup stumped.
推荐答案
一个可能的答案:sed -i 's/^$/hard rock:1008:70\nmisc:1009:22/' CD_list
One possible answer:
sed -i 's/^$/hard rock:1008:70\nmisc:1009:22/' CD_list
试试这个sed -i '$ a\hard rock:1008:70\nmisc:1009:22' CD_list
我认为这是您要使用的 a 命令.
I think it's the a command you're after.
这是一个很棒的资源:http://www.grymoire.com/Unix/Sed.html
这篇关于如何使用 sed 将多行附加到文件中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!