![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| compare two files | charandevu | Shell Programming and Scripting | 7 | 03-30-2008 12:20 PM |
| Compare files | kharen11 | UNIX for Advanced & Expert Users | 25 | 03-14-2007 01:35 AM |
| compare two txt files | space13 | Shell Programming and Scripting | 8 | 09-22-2006 06:40 AM |
| compare files and beyond | MizzGail | UNIX for Dummies Questions & Answers | 2 | 04-25-2003 10:34 AM |
| compare files | ingunix | UNIX for Dummies Questions & Answers | 3 | 05-24-2001 08:44 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
|||
|
compare 2 files..
Hello..I am trying to find solution for this:
I have 2 files A and B A: 1234 2345 3211 1111 5555 6666 7777 8888 9876 B: 1234 2345 3211 1111 5555 6666 9988 8899 2244 output should be: 9988 8899 2244 becouse that is difference between files. I tryed with diff...also I did something with sdiff and then grep "\>" U know to see just lines that are in certain file... can U help me with better solution..maybe awk?? thanks a lot.. |
| Forum Sponsor | ||
|
|
|
|||
|
Code:
awk '
BEGIN {
while ( getline < "A" ) { arr[$0]=1 }
}
{ if ( arr[$0] ~ /^ *$/ ) print FILENAME":" $0
else delete arr[$0];
}
END {
for( key in arr )
if ( key !~ /^ *$/ && arr[key] == 1) print "A:" key
} ' B
Code:
grep -vf A B grep -vf B A Code:
comm -23 A.sorted B.sorted comm -13 A.sorted B.sorted |
|
|||
|
Code:
#! /opt/third-party/bin/perl
open(FILE, "<", "a" ) || die "Unable to open file a <$!>\n";
while ( <FILE> ) {
chomp;
$fileHash{$_} = $i++;
}
close(FILE);
open(FILE, "<", "b" ) || die "Unable to open file a <$!>\n";
while( <FILE> ) {
chomp;
if( exists $fileHash{$_} ) {
}
else {
print "$_\n";
}
}
close(FILE);
exit 0
|
|
|||
|
I have made few changes to the awk code.
Code:
awk '
BEGIN {
while ( getline < "A" ) { arr[$0]=1 }
}
{ if ( arr[$0] != 1 ) print FILENAME":" $0
else delete arr[$0];
}
END {
for( key in arr )
if ( arr[key] == 1 ) print "A:" key
} ' B
Code:
while ( getline < "A" ) { arr[$0]=1 }
Code:
{ if ( arr[$0] != 1 ) print FILENAME":" $0
else delete arr[$0];
}
Code:
END {
for( key in arr )
if ( arr[key] == 1 ) print "A:" key
}
|