sed命令的a、c、q命令

在前面都已经知道了d、p、-n、s///g等的用法。

---------------------------------------------------

sed中,a命令是指在匹配的位置后面插入新的内容。

c命令是说将在匹配模式空间的指定行用新文本加以替代。

看例子:

zoer@ubuntu:~$ cat data
naughty is a boy
cc is a girl
zoer is naughty
zoer@ubuntu:~$ cat s
/^nau/a\
naughty\
is\
a\
boy
zoer@ubuntu:~$ sed -f s data
naughty is a boy
naughty
is
a
boy
cc is a girl
zoer is naughty

上面例子是a命令的例子。在以nau开头的行下面插入一些内容。

看c命令。

zoer@ubuntu:~$ cat s
/^nau/c\
naughty\
is\
a\
boy
zoer@ubuntu:~$ cat data 
naughty is a boy
cc is a girl
zoer is naughty
zoer@ubuntu:~$ sed -f s data
naughty
is
a
boy
cc is a girl
zoer is naughty

例子仅仅把a改成了c。结果就是以nau开头的行,被替换成了相应的内容。

-------------------------------------

q命令是说匹配到一定的行之后退出sed命令。

zoer@ubuntu:~$ cat data
cc is a girl
zoer is naughty
naughty loves cc.
cc loves naughty
zoer@ubuntu:~$ cat s
/^nau/q
zoer@ubuntu:~$ sed -f s data
cc is a girl
zoer is naughty
naughty loves cc.
zoer@ubuntu:~$ 

上面的例子,匹配到以nau开头的行,sed命令就终止了。

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值