sed 匹配多个字符串的行打印

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

grep hello\|world file > output

或者用扩展正则
code

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

若是grep用的是 -e 小写e参数,须要加上反斜杠转移,即:class

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

GNU sed 写法扩展

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

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

sed -n '/hello/p; /world/p'  file > output
相关文章
相关标签/搜索