3 ms·
The best part about using the @F array, is you get more than 10 things you can split and dereference. $0-9 only in awk. That and maybe because i'm an old perl
by mitchty 9y ago
The best part about using the @F array, is you get more than 10 things you can split and dereference. $0-9 only in awk.
That and maybe because i'm an old perl die hard, its just easier to pipe to perl than remember how awk does its shenanigans.
- kazinator 9y agoAwk is not limited to $0 to $9; where did you get that??? Maybe you're confusing this with register substitutions in regex: \1 through \9. The nice thing about the @F array is that @F[0] doesn't represent the whole record. There is a class of Awk bugs whereby arithmetic is being done on the parameters using $N (where N is some calculated variable containing an integer). Everything is fine when N >= 1, but if there is a bug where N is accidentally zero, then $N refers to the whole record instead of throwing an out-of-bounds error. And things are accidentally zero quite easily in awk, e.g. awk '{print $X}' # X is undefined so serves as zero; this prints all lines
- mitchty 9y agoSolaris awk. :)
- kazinator 9y agoI see on my Solaris 10 VM that indeed the "broken old awk" doesn't work past $9. However, on the same OS, "nawk" does.
- mitchty 9y agoYep, there is also /usr/xpg4/bin/awk vs /usr/ucb/bin/awk etc... I've long since had to deal with Solaris but for about 10 years of Solaris I always treat awk with a lowest common denominator approach. Which means I tend to avoid it even to this day.