Hi All,
First thanks for the help on earlier posts. I am receiving
an error running a script that written from an earlier post. I have tried to debug but have not delt with arrays much in the past the error I am receiving is as follows:
/u01awk: 0602-586 Cannot read the value of arr. It is an array name.
The Inptut line number is 8. The file is test.txt.
The source line number is 16.
My input file only has 8 lines and I have tried to change things but nothing has helped yet.
Please see the script Below. Sorry to be a bother!
# awk -f subTotal.awk test.txt
#--------------------------------------
BEGIN {
FS=":"
}
{
cell=$3 FS $4 FS $5
if (!arr[$1])
arr[$1]=cell;
else
arr[$1]=arr[$1] SUBSEP cell;
}
END {
for (i in arr) {
printf("%s", i);
numCellARR=split(arr, cellARR, SUBSEP)
allo=0; res=0; used=0;
for(j=1; j <= numCellARR; j++) {
split(cellARR[j], tmpCell, FS);
printf("\%s\t%s\t%s\n", tmpCell[1],tmpCell[2], tmpCell[3]);
allo+=tmpCell[1];
res+=tmpCell[2];
used+=tmpCell[3];
}
printf("Subtot; %s\t%s\t%s\n\n", allo, res, used);
}
}
#---------------------------------------
First thanks for the help on earlier posts. I am receiving
an error running a script that written from an earlier post. I have tried to debug but have not delt with arrays much in the past the error I am receiving is as follows:
/u01awk: 0602-586 Cannot read the value of arr. It is an array name.
The Inptut line number is 8. The file is test.txt.
The source line number is 16.
My input file only has 8 lines and I have tried to change things but nothing has helped yet.
Please see the script Below. Sorry to be a bother!
# awk -f subTotal.awk test.txt
#--------------------------------------
BEGIN {
FS=":"
}
{
cell=$3 FS $4 FS $5
if (!arr[$1])
arr[$1]=cell;
else
arr[$1]=arr[$1] SUBSEP cell;
}
END {
for (i in arr) {
printf("%s", i);
numCellARR=split(arr, cellARR, SUBSEP)
allo=0; res=0; used=0;
for(j=1; j <= numCellARR; j++) {
split(cellARR[j], tmpCell, FS);
printf("\%s\t%s\t%s\n", tmpCell[1],tmpCell[2], tmpCell[3]);
allo+=tmpCell[1];
res+=tmpCell[2];
used+=tmpCell[3];
}
printf("Subtot; %s\t%s\t%s\n\n", allo, res, used);
}
}
#---------------------------------------