LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Using master file for grep content (https://www.linuxquestions.org/questions/programming-9/using-master-file-for-grep-content-4175460886/)

keif 05-06-2013 08:07 AM

Using master file for grep content
 
Good morning,

I have a file containing UPCs like so:

Code:

03338367500
00000004166
03680017482
00000004048
85441700219
03680006320
61611231958
61611231958
50503721160
07102226001

I want to run a command/script that will allow me to grep each line one by one and put the results into a file. For instance:

Code:

grep line1 *.upc >> file1
grep line2 *.upc >> file1
grep line3 *.upc >> file1
...etc...

Of course I can run this manually on the command line over and over again. But is there a way to set up a script that will automatically grep each line from my master file one by one?

Please feel free to send me to homework, as I know this is limited information.

Thank you.

Keif

druuna 05-06-2013 08:31 AM

Have a look at grep's -f FILE, --file=FILE option.

grep - 2.1.2 Matching Control

danielbmartin 05-06-2013 09:01 AM

Quote:

Originally Posted by druuna (Post 4945909)
Have a look at grep's -f FILE, --file=FILE option.

Consider grep with both -f and -F options.

Daniel B. Martin

keif 05-06-2013 09:48 AM

The grep -f worked like a charm.

Thanks everyone!


All times are GMT -5. The time now is 08:56 AM.