GNU sed和UNIX sed 寫法不一樣
匹配多個關鍵詞,打印出匹配的行,效果類似於 grep
grep hello\|world file > output
或者用擴展正則
grep -E '(hello|world)' file > output
如果grep用的是 -e 小寫e參數,需要加上反斜杠轉移,即:
grep -e '\(hello\|world\)' file > output
GNU sed 寫法
sed -n '/hello\|world/p' file > output
這種寫法 UNIX的sed不支持,真是奇怪,UNIX的sed需要下面這樣的寫法,這種寫法GNU的sed也支持。
sed -n '/hello/p; /world/p' file > output
