grep和sed匹配多个字符关键字的用法

            GNU sed和UNIX sed 写法不一样

匹配多个关键词,打印出匹配的行,效果类似于 grep 

grep hello\|world file > output

或者用扩展正则

grep -'(hello|world)' file > output

 

如果grep用的是 -e 小写e参数,需要加上反斜杠转移,即:

grep -'\(hello\|world\)' file > output

GNU sed 写法

sed -'/hello\|world/p' file > output

 

这种写法 UNIX的sed不支持,真是奇怪,UNIX的sed需要下面这样的写法,这种写法GNU的sed也支持。

sed -'/hello/p; /world/p'  file > output
posted @ 2017-02-08 08:54  paul_hch  阅读(6549)  评论(0编辑  收藏  举报