Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I pass the resulting files from one grep pass to another so that I only grep through the subset with the second pass?

Tags:

linux

grep

bash

I want to be able to take the files I found with my first grep statement, something like this for example: grep -r Makefile * And then pass the files found in that pass of grep to a second grep with something like this for example: grep {files} '-lfoo'

How do I do this? I know there must be a way.

Thank you.

like image 510
NSA Avatar asked May 18 '10 00:05

NSA


People also ask

What does the '- V option to grep do?

-v means "invert the match" in grep, in other words, return all non matching lines.

How do I grep for a string in multiple files in a directory?

To search multiple files with the grep command, insert the filenames you want to search, separated with a space character. The terminal prints the name of every file that contains the matching lines, and the actual lines that include the required string of characters. You can append as many filenames as needed.


1 Answers

grep -l firstmatch * | xargs grep secondmatch {}
like image 161
Ignacio Vazquez-Abrams Avatar answered Oct 23 '22 11:10

Ignacio Vazquez-Abrams