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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Awk Array Error (From Prior Post) 2

Status
Not open for further replies.

jriordan

MIS
Sep 9, 2002
14
0
0
US
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(&quot;\%s\t%s\t%s\n&quot;, tmpCell[1],tmpCell[2], tmpCell[3]);
allo+=tmpCell[1];
res+=tmpCell[2];
used+=tmpCell[3];
}
printf(&quot;Subtot; %s\t%s\t%s\n\n&quot;, allo, res, used);
}
}

#---------------------------------------

 
Hi jriordan,

I suspect the problem might be with the line:


numCellARR=split(arr, cellARR, SUBSEP)


If I am not mistaken, the first argument should be a string, not an array.

Grant.


 
see my request in the orignal posted thread.

but......[ from the *original* posting ]

numCellARR=split(arr, cellARR, SUBSEP)

should be

numCellARR=split(arr, cellARR, SUBSEP)

vlad
+---------------------------+
|#include<disclaimer.h> |
+---------------------------+
 
Hi guys,

Ha! I think I see the problem.

vgersh99 -- you're using [ i ], but it gets displayed in italics as if it were a markup tag.

I did the same thing recently.

Grant.
 
darn TGML.............. - the original posting was correct though!

thanks Grant!!!

should be:

numCellARR=split(arr, cellARR, SUBSEP) vlad
+---------------------------+
|#include<disclaimer.h> |
+---------------------------+
 
Thanks for your help Guys!

That was it!

I truly appreciate it!
John
 
So vgersh99,

What do you do to make the [ i ] display normally? Slash out the '['?

It's a nuisance for me because I habitually use 'i' as a counter, and it often comes up in arrays.


Grant
 
just UNcheck 'Process TGML' selection at the bottom of the posting pane.

Click on 'Process TGML' link to see a list of the TGML tags/options.

I keep forgetting this every time I post code[/i].

vlad
+---------------------------+
|#include<disclaimer.h> |
+---------------------------+
 
Hi vgersh99,

Cool. I never clicked on those links before. Like Yogi Berra says, &quot;You can see a lot just by looking&quot;.

Thanks,
Grant
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top