Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Help creating HASH for file comparison

by samwyse (Scribe)
on Mar 27, 2013 at 20:21 UTC ( [id://1025809]=note: print w/replies, xml ) Need Help??


in reply to Help creating HASH for file comparison

If you're on a Unix system, don't use Perl. Sort each file on the second column, then use the 'join' command twice to find (a) lines that are common to both files, and (b) lines in one file that aren't in the other. The first group can then be further processed as desired.

# sort the first file by the second column (zero-indexed) sort -n -t , +1 f1 >s1 # sort the second file by the second column (zero-indexed) sort -n -t , +1 f2 >s2 # print lines whose second column (one-indexed) # are common to both files join -t , -1 2 -2 2 s1 s2 # print lines in file 1 that are NOT in file 2 join -t , -1 2 -2 2 -v 1 s1 s2

Replies are listed 'Best First'.
Re^2: Help creating HASH for file comparison
by space_monk (Chaplain) on Mar 27, 2013 at 21:14 UTC

    Don't use Perl?!? I think we have an outbreak of heresy in the lower orders! :-)

    A Monk aims to give answers to those who have none, and to learn from those who know more.
Re^2: Help creating HASH for file comparison
by jb60606 (Acolyte) on Mar 27, 2013 at 21:53 UTC
    unfortunately finding common lines is just the start. Once they're found, i'll need to compare subsequent fields and perform further processing beyond that. Perl is the only choice.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (12)
As of 2024-04-23 14:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found