sed如何插入多行和特殊字符
hqmb2 2019-01-30 06:51:18 [root@Client1-RHEL chap05]# cat -n datafile
1 northwest NW Charles Main 3.0 .98 3 34
2 western WE Sharon Gray 5.3 .97 5 23
3 southwest SW Lewis Dalsass 2.7 .8 2 18
4 southern SO Suan Chin 5.1 .95 4 15
5 southeast SE Patricia Hemenway 4.0 .7 4 17
6 eastern EA TB Savage 4.4 .84 5 20
7 northeast NE AM Main Jr. 5.1 .94 3 13
8 north NO Margot Weber 4.5 .89 5 9
9 central CT Ann Stephens 5.7 .94 5 1
问题1:
比如匹配north以后,我想插入多行
--->This is line 1<---
--->This is line 2<---
--->This is line 3<---
--->This is line 4<---
[root@Client1-RHEL chap05]# sed '/^north /a
> --->This is line 1<---
> --->This is line 2<---
> --->This is line 3<---
> --->This is line 4<---' datafile
sed: -e expression #1, char 13: unknown command: `-'
问题2:
如何正确插入特殊字符,比如IT'S里边的单引号
[root@Client1-RHEL chap05]# sed '/^north /a "IT'S A SECRET"' datafile
>
[root@Client1-RHEL chap05]# sed '/^north /a "IT\'S A SECRET"' datafile
>
尝试了两种方法,都直接接入多行编辑模式