Searching files for strings
How do I search a set of files for a particular string?
This will find the string but not report the file name:
cat *.txt | grep search-string
How do I get it to report the name of the file?
grep string files
Can you translate that into a command example?
grep string <files> is the command line for it.
For example if I type grep linux * in the /usr/src/linux directory I get a response like this:
REPORTING-BUGS:the command "sh scripts/ver_linux".
REPORTING-BUGS:[7.1.] Software (add the output of the ver_linux script here)
System.map:c020bed0 t udf_translate_to_linux
System.map:c0232fd0 T tioclinux
System.map:c03f32e8 D linux_banner
This shows me that REPORTING-BUGS and System.map have those lines in them with the string linux. There were obviously a lot more returned but I just wanted to show you an example of what the output looks like.
The reason why it didn't work the way you did it was all the text files were dumped to stdout and then directed into grep, so all the instances of the string it found were simply on stdout.
Thanks for the reply
Also, thanks for not saying RTFM (ie. man grep). I'm not a complete newbie so I should have known.
The cold must be affecting my brain. Yeh, thats it.
|All times are GMT -5. The time now is 10:29 AM.|