Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: Help creating HASH for file comparison

by samwyse (Scribe)
on Mar 27, 2013 at 20:21 UTC ( #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


Comment on Re: Help creating HASH for file comparison
Download Code
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 (Novice) 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
Node Status?
node history
Node Type: note [id://1025809]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (8)
As of 2014-07-29 05:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (211 votes), past polls