Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

comparing two files

Status
Not open for further replies.

rkckjk

IS-IT--Management
Apr 27, 2001
34
US
I have two files with each of them containing two columns(fields) of
data separated by a space. I need to read in both files into an array
I guess and compare the first column(field) of the first file with the
first column(field) of the second file. I have an example of the two
files below:

FileA FileB

rich fdfewfew john sdsd32das
tom 324dfdsfs bill sad213dsd
bill fdd34dsd ray dfdf3fdd
mary dsdfs3r steve fdfr4rfds
steve fdsf3zf rich sddsf3r43

I need the output from the comparison to show what FileA has the FileB
doesn't and what FileB has that FileA doesn't based on the comparison
of column(field one) only.

Example output:

Output from FileA Output from FileB

Tom 324dfdsfs john sdsd32das
mary dsdfs3r ray dfdf3fdd

So basically, how do I read in two files and compare the first field
of each file against each other and produce output using AWK.

Thanks


--------------------------------------------------------------------------------
 
something like that for starters:

nawk -v fn=fileA -f comm.awk fileB


#------------------- comm.awk
BEGIN {
if (!fn) fn = "fileA"
fileAprime= fn ".prime"
while((getline < fn) > 0)
arrA[$1] = $0
}

FNR == 1 { fileBprime= FILENAME &quot;.prime&quot; }

{
if ( !( $1 in arrA))
print $0 >> fileBprime;
else
delete arrA[$1];
}
END {
for (i in arrA)
print arrA >> fileAprime;
}


vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top