LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   Searching files for strings (https://www.linuxquestions.org/questions/linux-software-2/searching-files-for-strings-132738/)

tmoorman 01-08-2004 10:50 AM

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?
Thanks.

@@@ 01-08-2004 10:51 AM

grep string files

tmoorman 01-08-2004 11:05 AM

Can you translate that into a command example?

jtshaw 01-08-2004 11:52 AM

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.

tmoorman 01-08-2004 01:46 PM

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 05:42 PM.