LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices



Reply
 
Search this Thread
Old 01-08-2004, 11:50 AM   #1
tmoorman
Member
 
Registered: Aug 2003
Location: Ottawa, Ontario, Canada
Distribution: Kubuntu
Posts: 50

Rep: Reputation: 15
Question 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.
 
Old 01-08-2004, 11:51 AM   #2
@@@
Member
 
Registered: Dec 2003
Posts: 30

Rep: Reputation: 15
grep string files
 
Old 01-08-2004, 12:05 PM   #3
tmoorman
Member
 
Registered: Aug 2003
Location: Ottawa, Ontario, Canada
Distribution: Kubuntu
Posts: 50

Original Poster
Rep: Reputation: 15
Can you translate that into a command example?
 
Old 01-08-2004, 12:52 PM   #4
jtshaw
Senior Member
 
Registered: Nov 2000
Location: Seattle, WA USA
Distribution: Ubuntu @ Home, RHEL @ Work
Posts: 3,892
Blog Entries: 1

Rep: Reputation: 66
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.
 
Old 01-08-2004, 02:46 PM   #5
tmoorman
Member
 
Registered: Aug 2003
Location: Ottawa, Ontario, Canada
Distribution: Kubuntu
Posts: 50

Original Poster
Rep: Reputation: 15
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
group files by strings in dir Melsync Programming 7 12-17-2005 01:53 PM
bash script help (arrays and strings from files) nkoplm Programming 14 12-02-2005 10:50 AM
help searching files jorasmi Slackware 3 02-02-2005 05:06 AM
concatenating strings to open files veilig Programming 1 11-10-2003 06:36 PM
opening files with strings for file names veilig Programming 4 11-10-2003 12:19 PM


All times are GMT -5. The time now is 09:45 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration