using two values to find files

Hello,
I am not sure the best way to do this.  Have a need to search files , using two values.  If the files contain these two values then write the file name to a file called filenames.txt

I tried grep,   grep -e value1 -e value2 filename  

Is there another way to do this



thanks in advance for the help
bjeAsked:
Who is Participating?
 
woolmilkporcCommented:
I assume that the files must contain both values (logical AND).

grep -l "value1" $(grep -l "value2" filename) /dev/null > filenames.txt

filename can be wildcarded as usual (filename*, file*name etc).
It can also be a variable containing a list of names  like $files,
a file containing a list of files like $(<file_with_filenames)
or a subcommand producing such a list like $(ls /path/to/*.txt).

"/dev/null" is not a redirection target, it's just a dummy filename needed in case the grep between $(  ) wouldn't return any match.
0
 
bjeAuthor Commented:
Thank you
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.