sed: return last occurrence match until end of file

前端 未结 6 1441
名媛妹妹
名媛妹妹 2020-12-10 15:29

Using sed, how do I return the last occurance of a match until the End Of File? (FYI this has been simplified)

So far I\'ve tried:

sed -n \'/ Statist         


        
6条回答
  •  萌比男神i
    2020-12-10 16:23

    sed ':a;N;$!ba;s/.*Statistics/Statistics/g' INPUTFILE
    

    should work (GNU sed 4.2.1).

    It reads the whole file to one string, then replaces everything from the start to the last Statistics (word included) with Statistics, and prints what's remaining.

    HTH

提交回复
热议问题