DEV Community

Awk - A useful little language

Raunak Ramakrishnan on June 01, 2018

Awk is a small but capable programming language which is used for processing text. It was developed by Aho, Weinberger, Kerninghan at Bell Labs. J...
Collapse
 
leob profile image
leob

Nice intro/overview! Awk is great, I've used it a lot ... I remember I often used it to read/parse log files and then generate SQL using Awk, in order to perform database changes. It's very flexible for this kind of extract/transform/output work.

Collapse
 
rrampage profile image
Raunak Ramakrishnan

Some Awk one-liners replace my use of other Unix tools like cut, grep, join. Some people use perl as a better awk but I prefer the simplicity of Awk.

Collapse
 
leob profile image
leob

Awk is extremely flexible and easy to use. Can indeed replace cut/grep/join if you want to. And perl, never got into it, too complicated and cryptic, I prefer the C/javascript-like syntax of Awk.

Collapse
 
bauripalash profile image
Palash Bauri 👻

Awesome Article! Great Hands on tutorial ❤

Collapse
 
richardvk profile image
Richard vK

Best awk intro/summary I have read, thank you.

Collapse
 
ferricoxide profile image
Thomas H Jones II

Output formatting becomes much better when you ditch print in favor of printf.

Collapse
 
functionalstoic profile image
JasonSooter

That was a fun introduction. Glad to add that as a tool in my toolbelt

Collapse
 
samy80 profile image
Samuel A.

Nice intro, good pointers. Thanks!

Collapse
 
wangtiejun001 profile image
Matt Wang

The picture is enough for me, thanks the author!

Collapse
 
ishanigupta27 profile image
Ishani Gupta

Interesting! Just wondering why a whole new language for a feature? (Not to sound critical).

Are there any specialised optimizations specific to file i/o and parsing the file at lower level ? If so, it would be great to have it also as wrapper for other langaugaes. Any benchmarking ?

🙂🙂

Collapse
 
rrampage profile image
Raunak Ramakrishnan

Hi Ishani,

awk is a very old language (1977), predating scripting languages like perl and python. As part of Unix philosophy, it is used in combination with other Unix tools. It is simpler and faster to write than say a python script. Most awk uses are simple one-liners to extract particular columns.

It is indeed very fast as all it does is: For each line:

  • Check if line matches a pattern
  • Perform the associated action on the pattern

There was this famous article which showed that clever use of command-line tools can be several times faster than some big-data tools.

Collapse
 
reisclef profile image
Richard C

Very helpful! Thanks!

Collapse
 
stevezieglerva profile image
Steve Ziegler

LOVE AWK!!!!!!!!!!!

Collapse
 
lukaszkuczynski profile image
lukaszkuczynski

Wow, pandas in Bash ! Does it support cluster computing? ;)

Collapse
 
rrampage profile image
Raunak Ramakrishnan

It may replace your cluster :P
See this article on how a bash script is 235x faster than a Hadoop cluster.