LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 06-27-2014, 08:52 PM   #1
aori
LQ Newbie
 
Registered: Jun 2014
Posts: 1

Rep: Reputation: Disabled
Match file1 to file2 and remove non-matched lines by columns from file3


Hi,

I would appreciate your input on the following:

I want to match two files by there IDs (first column) and filter a third file by columns for only those IDs that match.

I have three files (see below). I would like to match file1$1 to the IDs in file2. Of those IDs that are equal between the two files, I would like to filter file 3 by columns. File 3 columns are ordered similarly to row1 of file1. The only difference is that ID names are not denoted as column names of file3. I only know that it has the same ordering.

file1:
ID X Y
ID1 X1 Y1
ID2 X2 Y2
ID3 X3 Y3

file2:
ID1
ID3

file3 (columns are in similar order as rows of file1 - only without actual IDs)
Z 1 2 3
W 1 2 3
V 1 2 3

output:
Z 1 3
W 1 3
V 1 3

How should I go about?

Thank you!

Anil
 
Old 06-28-2014, 02:33 AM   #2
John VV
LQ Muse
 
Registered: Aug 2005
Location: A2 area Mi.
Posts: 17,483

Rep: Reputation: 2610Reputation: 2610Reputation: 2610Reputation: 2610Reputation: 2610Reputation: 2610Reputation: 2610Reputation: 2610Reputation: 2610Reputation: 2610Reputation: 2610
please do not post your homework

WE will NOT do it for you

but if you are stuck then....
post the script you have and where it is failing

we can then point you in the right direction

also this was posted on
http://stackoverflow.com/questions/2...lues-by-column
 
  


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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Shell Script to replace specific columns on matched lines axl718 Programming 18 01-31-2013 06:12 PM
[SOLVED] sed and how to remove all lines after matched pattern transmutated Programming 5 06-13-2012 07:54 AM
extract matching lines from File2 based on File1. grep+while? pwd_pwd_omg_pwd Linux - Newbie 5 04-07-2009 01:48 PM
awk/gawk/sed - read lines from file1, comment out or delete matching lines in file2 rascal84 Linux - General 1 05-24-2006 09:19 AM
Avoid cat file1>>file2 automatic add return after file2. AshesOfTime Programming 5 11-25-2004 07:27 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 11:31 PM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration