I am running this command in a command prompt
gawk -f comparefirstandsecond.awk First.out Second.out
I want to do it in bash shell script and I am trying it like:
compareAwkOut=$(cat $diffedRowFromFirstFile | cat $diffedRowFromSecondFile | gawk -f $COMPARE_AWK_SCRIPT)
Where $diffedRowFromFirstFile | cat $diffedRowFromSecondFile are variables holding the file name with full path.
But it does not work, as my Awk script is looking for the actual names of the file to process and it needs to process both files in one go so the array that I create in the processing of the first file exists and I can compare it with contents of the second file.
comparefirstandsecond.awk
looks like this:
BEGIN {
FS=","
}
FILENAME~/^First.out$/ && /^[0-9a-zA-Z]*^^/,/^$/ {
if ( FILENAME~/Second.out/){
print "Second.out comes in here as well WHY ? it should not ... "
}else
{
print FILENAME;
for (i=1;i<=NF;i++) {
firstValues[i]=$i
}
}
}
FILENAME~/^Second.out$/ && /^[0-9a-zA-Z]*^^/,/^$/ {
print FILENAME;
#First.out does not come as it is already processed above
for (j=1;j<=NF;j++) {
secondValues[j]=$j
}
}
END {
printf "END\n";
#done something with both arrays for each values like
# for (x in firstValues) {
# printf("On count %s First %s and Second %s \n",x,firstValues[x],secondValues[x])
#if (firstValues[x]!=secondValues[x]) { }
}
}
If I cat them, the file names are lost, I think. It is just a data piped into gawk cat'ed together from both files.
gawk -f "$COMPARE_AWK_SCRIPT" "$diffedRowFromFirstFile" "$diffedRowFromSecondFile"