Use grep to report back only line numbers

前端 未结 8 1462
被撕碎了的回忆
被撕碎了的回忆 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:30

    To count the number of lines matched the pattern:

    grep -n "Pattern" in_file.ext | wc -l 
    

    To extract matched pattern

    sed -n '/pattern/p' file.est
    

    To display line numbers on which pattern was matched

    grep -n "pattern" file.ext | cut -f1 -d:
    

提交回复
热议问题