paul8339

            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

分类:

技术点:

相关文章:

  • 2021-11-27
  • 2021-11-27
  • 2021-11-27
  • 2021-11-27
  • 2021-11-27
  • 2021-11-20
  • 2021-11-27
猜你喜欢
  • 2021-11-27
  • 2021-11-27
  • 2021-12-22
  • 2021-11-27
  • 2021-11-27
  • 2021-07-25
  • 2021-11-27
相关资源
相似解决方案