Get line number while using grep
grep -n SEARCHTERM file1 file2 ...
If you want only the line number do this:
grep -n Pattern file.ext | gawk '{print $1}' FS=":"
Example:
$ grep -n 9780545460262 EXT20130410.txt | gawk '{print $1}' FS=":"
48793
52285
54023
Line numbers are printed with grep -n
:
grep -n pattern file.txt
To get only the line number (without the matching line), one may use cut
:
grep -n pattern file.txt | cut -d : -f 1
Lines not containing a pattern are printed with grep -v
:
grep -v pattern file.txt