LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 05-28-2013, 01:35 PM   #1
mathursiddarth
LQ Newbie
 
Registered: May 2013
Posts: 1

Rep: Reputation: Disabled
Smile Comparing fields in two lines


I have two text files.

File 1:
Quote:
1000|25|ab|ed|45|50
1000|26|ed|ft|5|52
1000|27|dq|hb|35|54
1000|28|aw|ju|16|56
File 2:
Quote:
25|ab|ed|0|100|500|600|700
27|dq|hb|0|323|344|233|442
I need to compare the $2 field of file 1 to the $1 field of file 2 and append the $6 field of file 2 to file 1.
That is, i need the following output in my file 1:
Quote:
1000|25|ab|ed|45|50|500
1000|27|dq|hb|35|54|344
Have been scratching my head for too long now.
Any help? Thank you so much
 
Old 05-28-2013, 03:22 PM   #2
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 18,505

Rep: Reputation: 3993Reputation: 3993Reputation: 3993Reputation: 3993Reputation: 3993Reputation: 3993Reputation: 3993Reputation: 3993Reputation: 3993Reputation: 3993Reputation: 3993
Quote:
Originally Posted by mathursiddarth View Post
I have two text files.
I need to compare the $2 field of file 1 to the $1 field of file 2 and append the $6 field of file 2 to file 1.
That is, i need the following output in my file 1:

Have been scratching my head for too long now.
Any help? Thank you so much
We'll be glad to help...post what you've written/tried so far. Otherwise, you could just read a line from file 1, grep for it in file 2, and (if it matches), and print out the results. You could assign each field to a variable for printing, use awk, or combinations of the two. There are lots of ways to do this.
 
Old 05-30-2013, 01:52 PM   #3
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,823

Rep: Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958
Why don't you try looking at some of the previous threads that have discussed the same general question? You can start with the ones in the Similar Threads box at the bottom of this page.
 
  


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
Comparing lines in two files? needhelp12 Linux - Newbie 3 11-12-2011 11:48 PM
[SOLVED] deleting fields in lines that have more fields than the average patolfo Linux - Software 4 09-14-2011 11:03 AM
[SOLVED] Comparing two fields in two files using Awk. Tauro Linux - Newbie 16 07-21-2011 12:47 AM
Deleting lines based on comparing fields..... OldGaf Programming 2 02-22-2008 07:04 AM
sql: highest value, comparing fields Ephracis Programming 6 06-01-2005 05:28 PM


All times are GMT -5. The time now is 05:01 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