标签:
三剑客之grep命令小结
1、 grep
(1)grep命令加-v参数表示不输出含有linux的内容
[root@Eric data]# cat abc
I am oldboy
oldboy
oldgirl
I am studying linux
I am Eric
[root@Eric data]# grep -v linux abc
I am oldboy
oldboy
oldgirl
I am Eric
(2)grep 直接加linux,表示输出含有linux内容的行,grep是按“行”输出的
[root@Eric data]# cat abc
I am oldboy
oldboy
oldgirl
I am studying linux
I am Eric
[root@Eric data]# grep linux abc
I am studying linux
(3)grep加正则表达式的用法^表示以什么为开头的,此例表示输出以old开头的内容
[root@Eric data]# grep ^oldboy abc
oldboy
[root@Eric data]# grep ^old abc
oldboy
oldgirl
[root@Eric data]# cat abc
I am oldboy
oldboy
oldgirl
I am studying linux
I am Eric
(4)grep搜索一x字符为结尾的字符
[root@Eric data]# grep x$ abc
I am studying linux
(5)grep –n带行数输出
[root@Eric data]# cat abc
I am oldboy
oldboy
oldgirl
I am studying linux
I am Eric
[root@Eric data]# grep -n oldboy abc
1:I am oldboy
2:oldboy
标签:
原文地址:http://www.cnblogs.com/Eric-bky/p/4281402.html