Asked • 05/29/19

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

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 -i null myfile.txt` returns example two null, example four null, How can I return matched lines together with their line numbers like this: example two null, - Line number : 2 example four null, - Line number : 4 Total null count : 2 I know -c returns total matched lines, but I don't how to format it properly to add `total null count` in front, and I don't know how to add the line numbers. What can I do?

1 Expert Answer

By:

Paul F. answered • 06/24/20

Tutor
4.9 (11)

IT and Math Tutor

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.