How to grep for contents after pattern?

前端 未结 7 935
礼貌的吻别
礼貌的吻别 2020-11-22 07:37

Given a file, for example:

potato: 1234
apple: 5678
potato: 5432
grape: 4567
banana: 5432
sushi: 56789

I\'d like to grep for all lines that

7条回答
  •  自闭症患者
    2020-11-22 08:19

    grep -Po 'potato:\s\K.*' file
    

    -P to use Perl regular expression

    -o to output only the match

    \s to match the space after potato:

    \K to omit the match

    .* to match rest of the string(s)

提交回复
热议问题