You’ve probably come across awk command and its most simple use: splitting string elements separated by blank spaces. In this short post I’d like to expand a little bit on using awk field separators.
To demonstrate, let’s inspect the output of ifconfig command on my Macbook:
Great! Now it should be fairly easy to use awk to get that IP address. Since it’s the second word from the left, we’re telling awk to print parameter 2, {print $2}:
** uses space as field separator by default, but you can also specify any other character to use as separator instead.
To continue with our example, I further parse the output (which is just the IP address at this stage) using . character as field separator:
I learn with Educative:
I'm also a fan of SetApp for macOS:
IT Consultancy
I'm a principal consultant with Tech Stack Solutions. I help with cloud architectrure, AWS deployments and automated management of Unix/Linux infrastructure. Get in touch!