linux grep 正则表达式一

发布时间:2015-01-31 14:26:14 阅读:1021次

1、^linux   以linux开头的行

2、 php$    以php结尾的行

3、 .   匹配任意单字符

4、 .+ 匹配任意多个字符

5、 .*  匹配0个或者多个字符

cd /var/www/html

touch test.php

vim test.php

php is very much

my age is 30

linux is very much 

x

my ip is 192.168.100.1

mysql is very much

y

Linux is very much


i like linux very much

i like linux

linux is veryvery much

linux is veryveryvery much

linux is veryveryveryvery much

linux is veryveryveryveryvery much

linux is veryveryveryveryveryvery much

root@localhost:/var/www/html#   grep -cni 'linux' test.php

root@localhost:/var/www/html#   grep -n 'linux' test.php|wc -l

root@localhost:/var/www/html#   grep -v 'linux' test.php

root@localhost:/var/www/html#   grep -E '^linux' test.php

root@localhost:/var/www/html#   grep -E  'linux$' test.php

root@localhost:/var/www/html#   grep -En  '.' test.php

root@localhost:/var/www/html#   grep -E  '.*'  test.php

root@localhost:/var/www/html#   grep -E  '.*linux.*' test.php

root@localhost:/var/www/html#   grep -E  ' .+linux.+' test.php

root@localhost:/var/www/html#   grep -E  ' ^$' test.php

root@localhost:/var/www/html#   grep -E  ' ^.$' test.php

root@localhost:/var/www/html#   grep -En  ' [0-9]+' test.php

root@localhost:/var/www/html#   grep -E  ' [0-9]+\.[0-9]+\.[0-9]+\.[0-9]+' test.php

root@localhost:/var/www/html#   grep -E  '(very)+' test.php

root@localhost:/var/www/html#   grep -E  ' (very){2}' test.php

root@localhost:/var/www/html#   grep -E  ' (very){2,4}' test.php

[root@db3 yansiyu]# grep -E --color '\b(very){3,4}\b' test.php    #查询行中包含3至4个very的句子
linux is veryveryvery much
linux is veryveryveryvery much

如有问题,可以QQ搜索群1028468525加入群聊,欢迎一起研究技术

支付宝 微信

有疑问联系站长,请联系QQ:QQ咨询

转载请注明:linux grep 正则表达式一 出自老鄢博客 | 欢迎分享