sed如何插入多行和特殊字符

hqmb2 hqmb2 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
[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
>
尝试了两种方法,都直接接入多行编辑模式
...全文

相关推荐

评论 3
收藏 已收藏
分享
返回顶部
hqmb2
Linux/Unix社区 23,224 成员 74,535 内容