Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re: Merging two data sets

by Jim (Curate)
on Jun 13, 2014 at 05:06 UTC ( [id://1089763]=note: print w/replies, xml ) Need Help??


in reply to Merging two data sets

C:\>perl -e "system('awk \"FNR == NR { if (FNR != 1) word[$1] = $2; ne +xt } $1 in word { print $0, word[$1] }\" DataSet2.txt DataSet1.txt')" A 12 45 hello A 10 12 hello A 15 74 hello C 11 41 blue C 18 12 blue B 23 15 goodbye D 19 10 happy D 11 12 happy E 14 5 black E 34 31 black C:\>cat DataSet2.txt id word A hello B goodbye D happy E black C blue C:\>cat DataSet1.txt id x1 x2 A 12 45 A 10 12 A 15 74 C 11 41 C 18 12 B 23 15 D 19 10 D 11 12 E 14 5 E 34 31 F 10 45 C:\>

And here's the pure AWK version…

C:\>awk "FNR == NR { if (FNR > 1) word[$1] = $2; next } $1 in word { p +rint $0, word[$1] }" DataSet2.txt DataSet1.txt A 12 45 hello A 10 12 hello A 15 74 hello C 11 41 blue C 18 12 blue B 23 15 goodbye D 19 10 happy D 11 12 happy E 14 5 black E 34 31 black C:\>

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1089763]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (4)
As of 2024-04-26 00:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found