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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
01-08-2004, 10:50 AM
|
#1
|
|
Member
Registered: Aug 2003
Location: Ottawa, Ontario, Canada
Distribution: Kubuntu
Posts: 50
Rep:
|
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
|
#2
|
|
Member
Registered: Dec 2003
Posts: 30
Rep:
|
grep string files
|
|
|
|
01-08-2004, 11:05 AM
|
#3
|
|
Member
Registered: Aug 2003
Location: Ottawa, Ontario, Canada
Distribution: Kubuntu
Posts: 50
Original Poster
Rep:
|
Can you translate that into a command example?
|
|
|
|
01-08-2004, 11:52 AM
|
#4
|
|
Senior Member
Registered: Nov 2000
Location: Seattle, WA USA
Distribution: Ubuntu @ Home, RHEL @ Work
Posts: 3,892
Rep:
|
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.
|
|
|
|
01-08-2004, 01:46 PM
|
#5
|
|
Member
Registered: Aug 2003
Location: Ottawa, Ontario, Canada
Distribution: Kubuntu
Posts: 50
Original Poster
Rep:
|
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.
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 12:27 AM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|