views:

25

answers:

1

Hello I am using grep recursive to search files for a string, and all the matched files and the lines containing that string are print on the terminal. But is it possible to get the line numbers of those lines too??

ex: presently what I get is /var/www/file.php: $options = "this.target", but what I am trying to get is /var/www/file.php: 1142 $options = "this.target";, well where 1142 would be the line number containing that string.

Syntax I am using to grep recursively is sudo grep -r 'pattern' '/var/www/file.php'

Hey one more question is, how do we get results for not equal to a pattern. Like all the files but not the ones having a certain string?

A: 

grep -nr SEARCHTERM file1 file2 ...

Miro A.
why did you mention two files?
sai
Hey it worked :D thank you Sir!
sai
Just as an example ...
Miro A.
If it worked, could you accept the answer please ?
Miro A.
I had another quick question, how do we get results for not equal to a pattern. Like all the files but not the ones having a certain string?
sai
that would be command line switch -v.If you run 'grep --help' it will display all options
Miro A.