Get the latest tech news

Idiomatic Awk (2010)


Here we'll see some hints on how to write more idiomatic (and usually shorter and more efficient) awk programs. Many awk programs you’re likely to encounter, especially short ones, make large use of these notions.

As mentioned above, awk assumes that it's time to replace FS with OFS (and thus recompute $0) when a field is modified, which is a sensible assumption, and almost always produces the output that one would expect. If you want to shorten it even more (and make it more cryptic) to impress your friends or whatever reason, you can move the assignments at the end to save the-v and remove some quotes: Here we see another typical idiom: a[$0] alone has the only purpose of creating the array element indexed by $0, even if we don't assign any value to it.

Get the Android app

Or read this on Hacker News

Read more on:

Photo of Idiomatic Awk

Idiomatic Awk

Related news:

News photo

Idiomatic Awk