Print last matching line?

后端 未结 5 768
無奈伤痛
無奈伤痛 2021-01-14 08:20

Using awk, I would like to print the last matching line of a file. I would like only the matching line itself, not any range of lines. I can use a command like

5条回答
  •  有刺的猬
    2021-01-14 08:44

    The command tail allows you to retreive the last n lines of an input stream. You can pipe your awk output into tail in order to trim off everything except the last line:

    awk '/foo/' bar.txt | tail -1
    

提交回复
热议问题