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 11-09-2005, 03:11 PM   #1
psweetma
LQ Newbie
 
Registered: Mar 2003
Distribution: Redhat 8.x
Posts: 12

Rep: Reputation: 0
Question Command to run another command against a list of files


Hi,

Can anyone prompt my memory on how to do this...

In the bash shell I have a recursive grep command which returns a list of matching files, e.g.

grep -rl mypattern .

I want to then grep over this list of files again to see which ones match another pattern. I believe I need to pipe the grep into a command which will run another arbitrary command (in this case my second grep) against the list of files that results from the first command (in this case my first grep), but I can't remember what it is....

Thanks,
P.
 
Old 11-09-2005, 03:46 PM   #2
psweetma
LQ Newbie
 
Registered: Mar 2003
Distribution: Redhat 8.x
Posts: 12

Original Poster
Rep: Reputation: 0
ah ok, i've just remembered, i was thinking of the 'xargs' command:

grep -rl '\.accept(' . | xargs grep -n '\.select('

P.
 
Old 11-09-2005, 04:26 PM   #3
Back_to_Linux
Member
 
Registered: Sep 2005
Location: PARIS
Distribution: Mandriva 10.0 Communoty
Posts: 117

Rep: Reputation: 15
#list=`grep -rl petern`
#grep -rl $list
or
#PATERN=your_patern
#grep -rl $PATERN $(grep -rl $PATERN $YOUR_PATH)
 
Old 11-09-2005, 06:29 PM   #4
psweetma
LQ Newbie
 
Registered: Mar 2003
Distribution: Redhat 8.x
Posts: 12

Original Poster
Rep: Reputation: 0
Smile

oh ok, i didn't realise you could also do it like that. i'm still learning about linux shells and bash.

thank you - this looks like a very powerful and fundamental mechanism.

P.
 
  


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
Is there a single command to list all hardware installed (command line)? davee Linux - Hardware 6 02-28-2009 08:19 PM
Command to select and move mutiple files from list in text file steve.paris Linux - Newbie 11 11-27-2005 01:44 PM
Command Line Help: Remove a List of Files lukasbradley Linux - Newbie 2 08-17-2005 05:21 AM
Command to list some files? AoiSora Programming 13 10-29-2003 05:37 PM
Command to list total number of files. WillieB_72 Linux - General 3 01-29-2003 10:25 PM


All times are GMT -5. The time now is 06:32 AM.

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