LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (http://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Select lines from FileA based on a key field in FileB (http://www.linuxquestions.org/questions/linux-newbie-8/select-lines-from-filea-based-on-a-key-field-in-fileb-862065/)

danielbmartin 02-11-2011 10:06 AM

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

grail 02-11-2011 10:26 AM

Maybe see if the '-f' option suits your needs?

danielbmartin 02-11-2011 11:37 AM

Of course! RTFM, and I did, but failed to understand/appreciate the -f options. Thank you, and SOLVED!

Daniel B. Martin


All times are GMT -5. The time now is 05:39 PM.