Say hello to AWK.
Disclaimer: Feel free to skip this story if you're familiar with AWK commands.
So, what's AWK? This is how Wikipedia defines it.
AWK is a programming language designed for text processing and typically used as a data extraction and reporting tool. It is a standard feature of most UNIX-like Operating Systems.
Let me break it down for you, it's a lot of fancy words IMHO for something relatively simple. If you have ever set up and managed servers, you would be familiar with commands like free
, htop
and ps aux
.
These commands usually give you a lot of data in a rather ugly format on your terminal and it makes life hell, particularly in some testing situations (Imagine prod being down and you see a bunch of data cramped together on your screen). Wouldn't it be nice just to get the data you want to see on your terminal? That's what AWK does for you. It helps you with text processing.
To give you an example, the Slack application on my MacBook stopped working a few minutes ago. It just kept loading. I wanted to kill the corresponding processes and restart slack, so I typed this command on my terminal.
ps aux | grep slack
Completely unrelated to the topic, I was rather being pissed about the internet being slow and the last thing I wanted to be was be more pissed off.
This is the result I got on executing the above command.
What the absolute hell, right? All I want is a PID, so I can kill the processes and move on with my life and respond to all the folks who would have pinged me on Slack. That's exactly where AWK helps.
ps aux | grep slack | awk '{print $2}'
The awk '{print $2}
part just prints the second column (which is the list of PIDs you would want in this particular case).
See, life's so much easier now.
AWK promises a lot more than this, treat this as a 101 to AWK or rather a life-hack.
Gotta go and kill those processes now! Thanks for reading this article.