Hi everybody,
I've been looking up and down and I haven't found a satifactorily answer to this.
What is the meaning of a single number in an awk statement, as in this piece of code, which removes the commas from the lines of a file:
or as in this statement, which prints the whole file as is:
So my question is more conceptual, regarding the presence of an integer in AWK. Is it a constant, or just a value that the shell needs, to evaluate to true the whole awk statement? How does it play out in AWK language as a whole? This is not clear to me !!
So can an expert shed some light on this ?
Secondly, when I try to access an array in the END statement of an AWK code, (which is built before the END statement), I have to change the subscript of the array to something else in order to print its values, as in this snippet:
Any ideas why is that so?
Thanks for your time
P.S.
Does anybody know any good site, or any other explanatory material on this and other AWK tricks? The books that I've read so far don't cover them well ?
I've been looking up and down and I haven't found a satifactorily answer to this.
What is the meaning of a single number in an awk statement, as in this piece of code, which removes the commas from the lines of a file:
Code:
awk 'BEGIN{FS=","}{$1=$1; OFS=""}[red]1[/red]' file # here number can be 1 or any other integer.
Code:
awk 1 file
So my question is more conceptual, regarding the presence of an integer in AWK. Is it a constant, or just a value that the shell needs, to evaluate to true the whole awk statement? How does it play out in AWK language as a whole? This is not clear to me !!
So can an expert shed some light on this ?
Secondly, when I try to access an array in the END statement of an AWK code, (which is built before the END statement), I have to change the subscript of the array to something else in order to print its values, as in this snippet:
Code:
awk '{ .....
..... array[$0]=$0 }
END { if ( k in array )
print array[k] # which works fine
# if I go : if ($0 in array ) print array[$0] --> doesn't work.
}
Thanks for your time
P.S.
Does anybody know any good site, or any other explanatory material on this and other AWK tricks? The books that I've read so far don't cover them well ?