How can I format my grep output to show line numbers at the end of the line, and also the hit count?

后端 未结 8 445
忘掉有多难
忘掉有多难 2021-01-29 17:46

I\'m using grep to match string in a file. Here is an example file:

example one,
example two null,
example three,
example four null,

grep

8条回答
  •  佛祖请我去吃肉
    2021-01-29 17:50

    use grep -n -i null myfile.txt to output the line number in front of each match.

    I dont think grep has a switch to print the count of total lines matched, but you can just pipe grep's output into wc to accomplish that:

    grep -n -i null myfile.txt | wc -l
    

提交回复
热议问题