sed的标签
-n 只打印模式匹配的行。
###替换字符串
[root@VM_0_16_centos sedDir]# [root@VM_0_16_centos sedDir]# cat Hello This is aaThis is bb[root@VM_0_16_centos sedDir]# sed 's/This/There/' Hello > output [root@VM_0_16_centos sedDir]# cat output There is aaThere is bb[root@VM_0_16_centos sedDir]#
###替换字符串
[root@VM_0_16_centos sedDir]# cat HelloThis is aaThis 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 aaThere 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 line1 This is the header line2 This is the first data line2 This is the first data line3 This is the third line3 This is the third line4 This is the second data line4 This is the second data line5 This is the laster line5 This is the laster line[root@VM_0_16_centos sedDir]# sed -n 'p' data 1 This is the header line2 This is the first data line3 This is the third line4 This is the second data line5 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]#