且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在模式之前和行号之后使用 sed 插入一行?

更新时间:2023-12-03 22:40:22

您可以编写一个 sed 脚本文件并使用:

You can either write a sed script file and use:

sed -f sed.script file1 ...

或者你可以使用(多个)-e 'command' 选项:

Or you can use (multiple) -e 'command' options:

sed -e '/SysAdmin/i
Linux Scripting' -e '1,$s/A/a/' file1 ...

如果你想在一行后附加一些东西,那么:

If you want to append something after a line, then:

sed -e '234a
Text to insert after line 234' file1 ...