grep线,在匹配模式后只包含一个单词(忽略空格)

时间:2015-08-10 09:40:43

标签: linux grep

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

实施例

(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?

---维沙尔

1 个答案:

答案 0 :(得分:0)

像这样?

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)

用括号更新答案。

相关问题