stevenrh has asked for the wisdom of the Perl Monks concerning the following question:
Hello All,
I am trying to compare two files, and send the difference to another file.
I have usernames in the first, and if they don't match the second, i want to print/redirect that username to the third file.
So far, I have some pseudo-code. My conflict lies in plain noobness. I am getting really bent on filehandles and arrays/hashes.
clarification
Essentially, I would like the iterpreter to read the first line of FILE1, if its paattern is matched on FILE2, continue to Line 2 of FILE1, and repeat check on FILE2.. Else, print to screen, or to another file. Here is what I have so far:
Thanks in advance for any help
clarification
Essentially, I would like the iterpreter to read the first line of FILE1, if its paattern is matched on FILE2, continue to Line 2 of FILE1, and repeat check on FILE2.. Else, print to screen, or to another file. Here is what I have so far:
#!/usr/bin/perl -w use strict; open(FIRST,"first.txt") || die "$!"; @first = <FIRST>; close FIRST; open(LAST,"last.txt") || die "$!"; @last = <LAST>; close LAST; foreach $i (@first){ if ($i =~ m/@last) }else{ print "$_"; }
Thanks in advance for any help
steven
Update:
no, this isn't homework :), a colleague and I are trying to match our userbase with the ones we've downloaded from our spam filter provider. we're trying to match/compare/contrast our username list with theirs (then we can batch upload our unfiltered and angry users' names). the file itself is under 1MB (about 40,000 lines). Diff doesn't work because they don't line up exactly, and grep -v -f etc.. choked on us as well. Perl seemed like my last straw.
UP-Update:
The code below satisfies my requirements for what I have to do. THANKS all!!!
--cheers
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: matching the contents of two (2) files
by dragonchild (Archbishop) on Mar 10, 2005 at 19:18 UTC | |
by Roy Johnson (Monsignor) on Mar 10, 2005 at 21:07 UTC | |
by dragonchild (Archbishop) on Mar 11, 2005 at 02:15 UTC | |
Re: matching the contents of two (2) files
by Roy Johnson (Monsignor) on Mar 10, 2005 at 20:59 UTC | |
Re: matching the contents of two (2) files
by bibo (Pilgrim) on Mar 10, 2005 at 19:21 UTC |
Back to
Seekers of Perl Wisdom