Use grep to report back only line numbers

前端 未结 8 1471
被撕碎了的回忆
被撕碎了的回忆 2020-12-04 13:40

I have a file that possibly contains bad formatting (in this case, the occurrence of the pattern \\\\backslash). I would like to use grep to return

8条回答
  •  南笙
    南笙 (楼主)
    2020-12-04 14:18

    All of these answers require grep to generate the entire matching lines, then pipe it to another program. If your lines are very long, it might be more efficient to use just sed to output the line numbers:

    sed -n '/pattern/=' filename
    

提交回复
热议问题