You recently posted scripts to carryout file comparisons. Why is the array "arrA" in the below BEGIN statement indexed by $1 i.e. arrA[$1]=$0, however...in the second example the array is indexed with an incrementer i.e. arr[++lineA]=$0
I know the scripts perform different tasks but I can't understand the logic behind the choice to
index the array - clearly it makes a difference.
=========================================
Subject: Comparing two files
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 ".prime" }
{
if ( !( $1 in arrA))
print $0 >> fileBprime;
else
delete arrA[$1];
}
END {
for (i in arrA)
print arrA >> fileAprime;
}
======================================
Subject: Can Two input files be processed at awk..?
BEGIN {
if (!fn) fn = "fileA"
lineA=0
while((getline < fn) > 0)
arr[++lineA] = $0
}
========================================
I would appreciate it if you could clear up the confusion.
Thanks
I know the scripts perform different tasks but I can't understand the logic behind the choice to
index the array - clearly it makes a difference.
=========================================
Subject: Comparing two files
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 ".prime" }
{
if ( !( $1 in arrA))
print $0 >> fileBprime;
else
delete arrA[$1];
}
END {
for (i in arrA)
print arrA >> fileAprime;
}
======================================
Subject: Can Two input files be processed at awk..?
BEGIN {
if (!fn) fn = "fileA"
lineA=0
while((getline < fn) > 0)
arr[++lineA] = $0
}
========================================
I would appreciate it if you could clear up the confusion.
Thanks