sed-学习记录

sed的标签

-n  只打印模式匹配的行。

 ###替换字符串

[root@VM_0_16_centos sedDir]# 
[root@VM_0_16_centos sedDir]# cat Hello 
This is aa
This is bb
[root@VM_0_16_centos sedDir]# sed 's/This/There/' Hello > output 
[root@VM_0_16_centos sedDir]# cat output 
There is aa
There is bb
[root@VM_0_16_centos sedDir]# 

  ###替换字符串

[root@VM_0_16_centos sedDir]# cat Hello
This is aa
This is bb
[root@VM_0_16_centos sedDir]# cat Hello | sed 's/This/There/' > output
[root@VM_0_16_centos sedDir]# cat output 
There is aa
There is bb
[root@VM_0_16_centos sedDir]#

 ###输出行号

#不带number的p,输出的全部的内容。

#带number的p,输出某一行。若number大于总行号,不输出。 number为非正整数,提示错误。

[root@VM_0_16_centos sedDir]# sed 'p' data 
1 This is the header line
1 This is the header line
2 This is the first data line
2 This is the first data line
3 This is the third line
3 This is the third line
4 This is the second data line
4 This is the second data line
5 This is the laster line
5 This is the laster line
[root@VM_0_16_centos sedDir]# sed -n 'p' data 
1 This is the header line
2 This is the first data line
3 This is the third line
4 This is the second data line
5 This is the laster line
[root@VM_0_16_centos sedDir]# sed -n '1p' data 
1 This is the header line
[root@VM_0_16_centos sedDir]# sed -n '2p' data 
2 This is the first data line
[root@VM_0_16_centos sedDir]# sed -n '66p' data 
[root@VM_0_16_centos sedDir]# 

猜你喜欢

转载自www.cnblogs.com/tsing0520/p/10188505.html
今日推荐