嗨,我想只匹配一个匹配模式后的单词。



(1)(xyz abc或def)

(2)(xyz pqr)

  If my matching pattern is xyz then  o/p should (xyz pqr).

   I want to grep line which contains only one word (ignore white space) after pattern is matched.

  So how can I do?


---维萨尔

最佳答案

像这样?

grep '\bxyz\s*\w*)$' file


如果需要格式后的单词,请使用'\bxyz\s*\w\+)$'

与你的例子:

kent$  cat f
(xyz abc or def)

(xyz   pqr)
LsyHP 12:46:30 /tmp/test
kent$  grep '\bxyz\s*\w\+)$' f
(xyz   pqr)


用括号更新了答案。

关于linux - 模式匹配后的grep行仅包含一个单词(忽略空白),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/31916271/

10-13 09:36