Awk: What is the difference between: X[a,b,c] - X[a][b,c] - X[a][b][c]
I have awk appearing to behave inconsistently. With the same variable it will give the message:
and, if I try to correct that, then:
I'm using a three dimensional array. There seems to be a significant difference to how awk - GNU Awk 4.1.4, API: 1.1 (GNU MPFR 3.1.5, GNU MP 6.1.2) - treats the following:
What is the difference between these? Where can I find it documented?
To demonstrate, with a small piece of code:
$ awk -f demo.awk </dev/null
As the code says, in the last example, if I try
which seems the correct syntax, it gives the error
.
Awk, in this case, particularly, gawk, has supported multidimensional arrays for a long time. On linux, 'awk' is usually 'gawk', so the distinction isn't important.
You can see one manual entry here:
It seems there are two mechanisms. In the case of:
awk (gawk) it uses a separator character, known as 'SUBSEP'. So you can get 'a' and 'b' above by:
gawk also provides 'true' arrays. What I'm trying to understand is the difference between these. The manual page is:
The version is:
---------- Post updated at 01:37 PM ---------- Previous update was at 01:06 PM ----------
OK, I think I've worked out the answer.
The two types of array are entirely different and incompatible. You cannot use split if you define the array as X[a][b][c].
It does allow you to mix the two types, as in X[a][b,c], as I did, but it is a really bad idea to do this as it seems to confuse the interpreter - this was my problem.
Here is some working code that sets up, then lists, the elements in the three dimensional array correctly - no use of split and it's OK.
Output:
This User Gave Thanks to Fustbariclation For This Post:
Hi,
I have a file which consists of the following information in repeating blocks.
************First iteration***************
xr_lab#show memory compare start
Thu Sep 19 14:38:06.400 WIB <<<<<<<<<< START TIME
Successfully stored memory snapshot in... (3 Replies)
In the awk I am trying to subtract the difference $3-$2 of each matching $4 before the first _ (underscore) and print that value in $13.
I think the awk will do that, but added comments. What I am not sure off is how to add a line or lines that will add sum each matching $13 value and put it in... (2 Replies)
so, im going over one of my scripts and trying to optimize it.
i have a code like this:
cksum sjreas.py | awk '{prinnt $1$2}'
This does what I need. However, i dont want to call the external command awk. so im doing this:
cksum sjreas.py | while OFS=' ' read v1 v2 ; do printf... (4 Replies)
What is the difference in these two awk command? Both returns same output but I am not sure what is the use of +0 in command 1.
awk -F "," '{print $1+0,$2+0,$3+0}'
awk -F "," '{print $1, $2, $3}' (3 Replies)
Hi..I have the data in a file like in this format, and I need the output time difference in seconds by using awk command. Start date/time and end date/time given in column 2,3 & 4,5. Please assist how to write shell script.
File1.txt
JOB1 10/09/2013 17:42:16 10/09/2013 17:43:46 SU 6202685/1... (4 Replies)
This should be a really easy question.
My input file will have a few fields that are strings in the first line, which I will extract and save as variables. The rest of the fields on every line will be integers and floating point numbers. Can awk tell the difference somehow? That is, is there... (5 Replies)
Hi,
I've got what is probably quite an easy little (presumably) awk problem that I just can't seem to work out (mental block...I've already spent ages getting the data into this format!). I want to work out the difference between rows for certain columns. for example:
1359142876 RED 14... (3 Replies)
Hey there,
I just stumbled upon a difference between using awk on the commandline and using it in a shellscript.
I have a variable, e.g.: PROG=vim
then i want to check if the package with this name is installed: TEMPVAL=$(dpkg -l | awk '{ if ($2 == "$PROG") print $2 }') (Im using... (10 Replies)
Hello again,
I've run into another problem that I've been unable to solve. With everyone's help last time, the script worked perfectly! This problem takes a little more finesse, and the bash script I thought up didn't work, so I've canned it. I'd like to try awk if possible. Here's my... (6 Replies)
Hi all,
I have a requirement for a script to find out the increase in memory. We have a log native_stderr.log where this will log.
bash-2.05$ tail -40 native_stderr.log | grep ': freed'
<GC(4140): freed 168190456 bytes, 66% free (180990488/271776256), in 253 ms>
<GC(4141): freed... (4 Replies)