Re:Understanding Awk
by tyingq on Thursday September 30, 2021 @12:51PM
(#28708415)
The syntax isn't nearly as nice, but Perl can be handy if you're doing something more after splitting into columns. And it's usually already there / installed, like awk. For just columns:
[ Parent
| on HN ]
Re:Understanding Awk
by adamgordonbell on Thursday September 30, 2021 @01:05PM
(#28708571)
It surprized me that AWK had dictionaries and no declaration of vars that make it feel like a modern scripting langauge even though it was written in the 70s.
It turns out though that this is because Perl and later Ruby were inspired by AWK and even support these line by line processing idioms with BEGIN and END sa well.
ruby -n -a -e 'puts "#{$F[0] $F[1]}"'
ruby -ne '
BEGIN { $words = Hash.new(0) }
$_.split(/[^a-zA-Z]+/).each { |word|
$words[word.downcase] += 1 }
END {
...
Re:Understanding Awk
by tannhaeuser on Friday October 01, 2021 @01:57AM
(#28715128)
I think it's pretty obvious that awk syntax is ultimately the main inspiration for JavaScript syntax, with optional semicolon as stmt terminator, regexp literals, for (x in y), the function keyword, a[x] associative array accessors, etc.