linux系统中sed复合命令

1、

[root@PC3 test]# cat c.txt
1
2
3
4
5
6
7
8
9
10

2、将2替换为xxxx,将5替换为yyyy,将7替换为zzz,删除匹配9的行,在第一行前增加first

[root@PC3 test]# sed 's/2/xxxx/; s/5/yyyy/; s/7/zzz/; /9/d; 1i first' c.txt
first
1
xxxx
3
4
yyyy
6
zzz
8
10
[root@PC3 test]# sed -e 's/2/xxxx/' -e 's/5/yyyy/' -e 's/7/zzz/' -e '/9/d' -e '1i first' c.txt
first
1
xxxx
3
4
yyyy
6
zzz
8
10
[root@PC3 test]# sed -e 's/2/xxxx/' -e 's/5/yyyy/' -e 's/7/zzz/' -e '/9/d' -e '1i first' -e '1a second' c.txt
first
1
second
xxxx
3
4
yyyy
6
zzz
8
10
原文地址:https://www.cnblogs.com/liujiaxin2018/p/14344449.html