LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices



Reply
 
Search this Thread
Old 02-11-2011, 11:06 AM   #1
danielbmartin
Senior Member
 
Registered: Apr 2010
Location: Apex, NC, USA
Distribution: Ubuntu
Posts: 1,165

Rep: Reputation: 306Reputation: 306Reputation: 306Reputation: 306
Select lines from FileA based on a key field in FileB


I want to select lines from FileA based on a key field in FileB.

egrep does this nicely:
"egrep -w '0132874|0132880|0100765' < " FileA

Suppose FileB consists of three lines:
0132874
0132880
0100765

Is there a way to code egrep to do the selection?

I really like code which does not use explicit loops so my interest is to find a grep or egrep or sed (or some other) command to perform this function.

Neither file is sorted on the key field but they could be. There is no requirement to keep the files in their present order.

We may assume that each key value in each file is unique.

Thanks!

Daniel B. Martin
 
Old 02-11-2011, 11:26 AM   #2
grail
Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 7,692

Rep: Reputation: 1987Reputation: 1987Reputation: 1987Reputation: 1987Reputation: 1987Reputation: 1987Reputation: 1987Reputation: 1987Reputation: 1987Reputation: 1987Reputation: 1987
Maybe see if the '-f' option suits your needs?
 
Old 02-11-2011, 12:37 PM   #3
danielbmartin
Senior Member
 
Registered: Apr 2010
Location: Apex, NC, USA
Distribution: Ubuntu
Posts: 1,165

Original Poster
Rep: Reputation: 306Reputation: 306Reputation: 306Reputation: 306
Of course! RTFM, and I did, but failed to understand/appreciate the -f options. Thank you, and SOLVED!

Daniel B. Martin
 
  


Reply

Tags
egrep, grep, sed


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
Equivalence classes, based on field values and multi-key hashtable openSauce Programming 5 05-16-2010 09:35 PM
use awk to read and update FileA and FileB at the same time magische_vogel Linux - Newbie 18 07-01-2009 01:21 PM
Firefox and URL field select-all in Linux? brianpbarnes Linux - Software 2 02-03-2009 10:34 AM
Deleting those lines that doent have 3rd field raghu123 Programming 3 08-29-2008 12:35 AM
BASH Scripting - printing select lines in a file bullfrog1870 Linux - Newbie 16 11-08-2006 10:33 AM


All times are GMT -5. The time now is 10:32 AM.

Main Menu
Advertisement
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