LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 05-06-2013, 08:07 AM   #1
keif
Member
 
Registered: Apr 2013
Posts: 80

Rep: Reputation: Disabled
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
 
Old 05-06-2013, 08:31 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374
Have a look at grep's -f FILE, --file=FILE option.

grep - 2.1.2 Matching Control
 
2 members found this post helpful.
Old 05-06-2013, 09:01 AM   #3
danielbmartin
Senior Member
 
Registered: Apr 2010
Location: Apex, NC, USA
Distribution: Ubuntu
Posts: 1,099

Rep: Reputation: 288Reputation: 288Reputation: 288
Quote:
Originally Posted by druuna View Post
Have a look at grep's -f FILE, --file=FILE option.
Consider grep with both -f and -F options.

Daniel B. Martin
 
2 members found this post helpful.
Old 05-06-2013, 09:48 AM   #4
keif
Member
 
Registered: Apr 2013
Posts: 80

Original Poster
Rep: Reputation: Disabled
The grep -f worked like a charm.

Thanks everyone!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] SOLUTION: named: loading from master file managed-keys.bind failed: file not found catkin Linux - Server 2 11-08-2011 02:51 PM
Dividing content of one file by content of another larspend Linux - Newbie 5 04-12-2011 08:00 PM
Content Filtering - using grep hiteshthappa Linux - Newbie 2 07-15-2008 04:11 PM
grep output on stdout and grep output to file don't match xnomad Linux - General 3 01-13-2007 04:56 AM


All times are GMT -5. The time now is 09:41 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration