I have this script:
find . -name "$2" -print | xargs grep --colour=auto "$1"
It searches for a $1 word in $2 matching files. How can I make it print the line number on which the word has been found.
Thanks
You don't need to use find
and xargs
here. You can use recursive grep like this:
grep -RHn --colour=auto "$1" --include='$2' .
Options:
-n # for printing line numbers
-R # for recursive grep
-H # for printing file names
From man grep
:
-n, --line-number
Prefix each line of output with the 1-based line number within its input file. (-n is specified by POSIX.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With