LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
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-27-2016, 01:16 PM   #16
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,006

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191

Well I am not sure why the '!' was giving you weird information but the single quotes would not have made it done anything good, I would suggest the results were just lucky.

Using your new input data and changing field 2 for 3 I get the correct results for both files irrelevant of order:
Code:
$ awk 'FNR==NR{a[$3$4] = $1;next}a[$3$4] && a[$3$4] != $1' f1 f2
Dc id 168 20
P d 76 0
P f 76 19
V d 75 0
V f 75 19
G f 9 19
G t 9 18
$ awk 'FNR==NR{a[$3$4] = $1;next}a[$3$4] && a[$3$4] != $1' f2 f1
Di i 168 20
Mm d 75 0
Mm f 75 19
Mv d 76 0
Mv f 76 19
n f 9 19
n t 9 18
I hand checked all results and they are correct.

Good luck with the python solution.
 
Old 05-29-2016, 02:14 PM   #17
danielbmartin
Senior Member
 
Registered: Apr 2010
Location: Apex, NC, USA
Distribution: Mint 17.3
Posts: 1,881

Rep: Reputation: 660Reputation: 660Reputation: 660Reputation: 660Reputation: 660Reputation: 660
Quote:
Originally Posted by grail View Post
[code]
$ awk 'FNR==NR{a[$3$4] = $1;next}a[$3$4] && a[$3$4] != $1' f1 f2
A wonderful concise solution. Testing reveals a minor oversight.

With InFile1 ...
Code:
Di i 168 20
aa bb 5 66
... and InFile2 ...
Code:
Dc id 168 20
cc dd 56 6
... the code given in post #16 gives this result ...
Code:
Dc id 168 20
cc dd 56 6
... but the correct results are ...
Code:
Dc id 168 20
This "band aid" fix works ...
Code:
awk 'FNR==NR{a[$3"~"$4] = $1;next}a[$3"~"$4] && a[$3"~"$4] != $1' f1 f2
... but perhaps you have a nicer one.

Daniel B. Martin

Last edited by danielbmartin; 05-29-2016 at 04:11 PM. Reason: Improved wording.
 
Old 05-29-2016, 02:18 PM   #18
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,006

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
Good pick up Daniel. I would just use a comma which will place SUBSEP between each, but any character like your suggestion is fine too
 
1 members found this post helpful.
  


Reply



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
Matching two fields between two files with awk bop-a-nator Linux - Newbie 5 04-30-2013 11:51 AM
compare first column of 2 files with awk Vthimmap Linux - Newbie 5 11-09-2012 02:59 AM
[SOLVED] awk pattern matching between huge files? rare_aquatic_badger Programming 8 05-19-2012 06:43 AM
[SOLVED] awk with pipe delimited file (specific column matching and multiple pattern matching) lolmon Programming 4 08-31-2011 12:17 PM
[SOLVED] AWK (or TCL/TK): Matching rows and columns between multiple files Euler2 Programming 6 05-30-2011 06:31 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:43 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
Open Source Consulting | Domain Registration