Hello.

How can I enumerate the lines that are obtained as a result of searching for lines from grep ?

For example, I grep "mystring" file.txt : grep "mystring" file.txt . At the output, I get something like:

My home - it's mystring
Dont mysqtring
Jony mysqtring jastin

And I need:

  1. My home - it's mystring
  2. Dont mysqtring
  3. Jony mysqtring jastin
  • Do you happen to know how to close the question? - frops
  • @FordMustang, there are links to the question [edit], [close], ... Maybe there are not enough points yet? Then I can close. - avp
  • @avp Yes, if you can) - frops
  • Hmm, what's the point of closing the question? Suddenly, someone will come up with another good answer? - VladD
  • The issue is resolved) - frops

2 answers 2

 grep "mystring" file.txt | cat -n 

    It will be more correct

     grep -n "mystring" file.txt 

    and run faster

    • 2
      As I understand it, in this case, the line numbers in the required file will be displayed, but this is not exactly what is needed, but thanks anyway. - frops
    • one
      Yes, you are right) - ArcherGodson