LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 01-21-2006, 04:18 AM   #1
carl0ski
Member
 
Registered: Sep 2004
Location: Melbourne, Victoria Australia
Distribution: Support those that support you :)
Posts: 872
Blog Entries: 12

Rep: Reputation: 30
Grep String Search, and identify source file.


hey
i havent figured what string of pipes and Command will allow me to display the filename in which 'grep string' finds.

cat *.fxd | grep Comedy

Code:
<genre>Adventure / Comedy</genre>
      <genre>Comedy</genre>
      <genre>Comedy / Drama</genre>
      <genre>Adventure / Comedy</genre>
      <genre>Action / Adventure / Comedy</genre>
      <genre>Comedy</genre>
      <genre>Comedy</genre>
      <genre>Comedy</genre>
      <genre>Action / Comedy / Crime</genre>
how can i show the above seperated by it's filename. or even grab the file name


Note i find the solution script will be, very interesting to locate what file store what settings
 
Old 01-21-2006, 04:43 AM   #2
spooon
Senior Member
 
Registered: Aug 2005
Posts: 1,755

Rep: Reputation: 51
Code:
grep Comedy *.fxd
 
Old 01-21-2006, 05:32 AM   #3
Bebo
Member
 
Registered: Jul 2003
Location: Göteborg
Distribution: Arch Linux (current)
Posts: 553

Rep: Reputation: 31
If you're interested in what files match your search string but not exactly how they match, use the -l switch, like so: grep -l string files. In your case: grep -l Comedy *.fxd
 
Old 01-21-2006, 06:55 AM   #4
bulliver
Senior Member
 
Registered: Nov 2002
Location: British Columbia, Canada
Distribution: Gentoo x86_64; FreeBSD; OS X
Posts: 3,764
Blog Entries: 4

Rep: Reputation: 78
From grep manpage:
Quote:
-l, --files-with-matches
Suppress normal output; instead print the name of each input file from which output would normally have been printed. The scanning will stop on the first match.
I don't think that's what he wants. spooon's answer is correct, because by default grep will print the filename on multiple file searches. The reason it isn't working for carl0ski is because of the RUOC (redundant use of 'cat') which means grep is being run individually for each file catted, rather than a single run.

So, as spoon so helpfully wrote:
Code:
grep Comedy *.fxd
will do the trick...
 
Old 01-21-2006, 09:15 AM   #5
carl0ski
Member
 
Registered: Sep 2004
Location: Melbourne, Victoria Australia
Distribution: Support those that support you :)
Posts: 872

Original Poster
Blog Entries: 12

Rep: Reputation: 30
Quote:
Originally Posted by bulliver
From grep manpage:


I don't think that's what he wants. spooon's answer is correct, because by default grep will print the filename on multiple file searches. The reason it isn't working for carl0ski is because of the RUOC (redundant use of 'cat') which means grep is being run individually for each file catted, rather than a single run.

So, as spoon so helpfully wrote:
Code:
grep Comedy *.fxd
will do the trick...

i really can't believe i was that stupid i completely over complicated it somehow :S.
 
  


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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
can you specify which files to grep search? sneakyimp Linux - Software 4 10-12-2005 09:28 PM
use grep and execute a command if string is found plisken Linux - General 6 07-28-2005 12:06 PM
how to grep only one string pr match gummimann Linux - General 3 11-06-2003 10:40 AM
grep - finding string and replacing with new ckibler Linux - Newbie 6 08-01-2003 07:25 PM
Grep for search, but what for replace? TheSpecial Linux - Software 18 04-28-2003 10:01 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 03:39 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
Open Source Consulting | Domain Registration