Possible Duplicate:
Use grep to report back only line numbers
I only want to see the line number. I don't need to see the remaining output.
Possible Duplicate:
Use grep to report back only line numbers
I only want to see the line number. I don't need to see the remaining output.
Pipe your grep -n
output, which normally looks something like:
11: stuff that matched
43: more stuff that matched
through sed to strip out the matching parts:
grep -n pattern file | sed -e 's/:.*//g'
11
43
grep -n
or --line-number
option will do this for you. You can find this information in the grep help file, which you can find by using grep --help
or grep --help | less
to read it more carefully. Also consider using the manual page: man grep
You could use awk
too.
grep -n word file | awk -F: '{ print $1 }'
As @Barmar pointed out you could just use an awk
one-liner as such:
awk '/regex/ { print NR }' file
Since you don't have awk
you could also use cut
:
grep -n word file | cut -d: -f1