Reason 2,147,019 Why awk is Awesome

Even decades after its initial creation, the command line utility awk is awesome. It's more than a command line - it's an entire programming language for manipulating files. Sure, it's possible to write code in other languages to perform the same functionality but then it is necessary to install something (Python, Java, some program, etc.). The awk command exists right out of the box on Lunix and when all that is necessary is a quick one off, awk still rocks.

Just in case there is still confusion over what awk means, it's the initials of the creators: Aho, Weinberger and Kernighan.

This post isn't a tutorial on awk, there are plenty already and some are really good, rather this post is about a real world problem and a really simple solution that doesn't take much effort.

While developing, there were some intermediate files created in the form of key-tab-jsondata terminated with a carriage return. Example:

Key	{ "big": "block", "of": "json" }
Key2 	{"another": "chunk",  "of": "json"}

For a quick experiment, the key was necessary as the investigation only required inspecting the json data. What was necessary was a quick way to strip off the key, and keep each chunk of json data on an individual line. Since this processing was being performed on a Linux machine, awk was readily available.

Assume that the data above is store in a file called "ummy_file" and the output will be written into "dummy_file_cut". With these conditions, awk can be employed to reformat the file. The command line is:

awk -F '[.]*\t[.]*' '{print $2}' dummy_data > dummy_data_cut

Which results in (output of cat dummy_data_cut):

{ "big": "block", "of": "json" }
{"another": "chunk",  "of": "json"}

Solved, with one command line.