+ -
当前位置:首页 → 问答吧 → 大家好,为何只输出了一次匹配?

大家好,为何只输出了一次匹配?

时间:2011-04-23

来源:互联网

大家好,有如下文本3个hello在一行

hello hello hello

我用
  1. perl -lne 'print "$1" if /(hello)/' test.txt
复制代码
控制台只输出一个hello ,曾看到一文章提到这问题的,忘了在哪里看过,因为好久没处理文本了,

如果我要在控制台输出三个hello,怎么写这个one liner呀. 谢谢啊.

作者: perlnewbie   发布时间: 2011-04-23

-n 是按行处理的

作者: zhlong8   发布时间: 2011-04-23

perl -lne 'print "$1" while /(hello)/g' test.txt

作者: ziyunfei   发布时间: 2011-04-23

原来是这样呀,非常感谢呀.

作者: perlnewbie   发布时间: 2011-04-24