Corey Glidden
Corey Glidden

Reputation:

How do I search a directory of files using another file as input and sending the output to another file?

I am working on a Unix system. I have a directory of files called MailHistory. Each file in the directory contains all of the emails for the previous day.
The files are created at midnight and named with the timedatestamp. So, a typical filename is 20090323000100.

I have a file that has a list of names. Using this file as input, I need to search the MailHistory directory. The results of the search need only return the filename of the file that contains the name being searched.

This is an example of the names in the file: GADDIS, SHUREE V. HERWEYER, JILL RENEE KAPENGA, TRICIA JAMI MOTON, VIOLA NELSON, TAMMY K OBERLIN, DAVID LYNN PALS, WILLIAM BRYANT PEARSON-BUNCH, ELESE

The emails will have names in the same format (LASTNAME, FIRSTNAME MIDDLENAME) and case (UPPER). I want to send the output to a file.

Thanks in Advance, Corey

Upvotes: 2

Views: 216

Answers (3)

ashawley
ashawley

Reputation: 4283

grep -rlFf names_file MailHistory > matches

Upvotes: 1

zuzur
zuzur

Reputation:

cat list | xargs -I{} grep -l "SHUREE V\. HERWEYER" {} > matches

Remember you'll need to escape () dots in the search string

Upvotes: 0

gpojd
gpojd

Reputation: 23075

grep -l SEARCH_TERM -r MailHistory

or, if you don't want to recursively check the directory:

cd MailHistory; grep -l SEARCH_TERM *; cd -

Upvotes: 0

Related Questions