LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   Command to run another command against a list of files (https://www.linuxquestions.org/questions/linux-general-1/command-to-run-another-command-against-a-list-of-files-381531/)

psweetma 11-09-2005 02:11 PM

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.

psweetma 11-09-2005 02:46 PM

ah ok, i've just remembered, i was thinking of the 'xargs' command:

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

P.

Back_to_Linux 11-09-2005 03:26 PM

#list=`grep -rl petern`
#grep -rl $list
or
#PATERN=your_patern
#grep -rl $PATERN $(grep -rl $PATERN $YOUR_PATH)

psweetma 11-09-2005 05:29 PM

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.


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