How to grep for contents after pattern?

前端 未结 7 1019
礼貌的吻别
礼貌的吻别 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:16

    sed -n 's/^potato:[[:space:]]*//p' file.txt
    

    One can think of Grep as a restricted Sed, or of Sed as a generalized Grep. In this case, Sed is one good, lightweight tool that does what you want -- though, of course, there exist several other reasonable ways to do it, too.

提交回复
热议问题