Custom awk delimiters

Software

In our continuing series of things you already know unless you don’t, say you want to process a string in awk using a delimiter other than a space, or as awk referres to as a field seperator:

$ echo "Bird'is'the'Word" | awk '{ print $1 }'
==> "Bird'is'the'Word"

You use the -F argument to split on a different character. I used a single quote here to remind us to escape characters if needed, or wrap in quotes:

$ echo "Bird'is'the'Word" | awk -F\' '{ print $1 }'
==> Bird

This works in the One True Awk™ found on BSDs, macOS and illumos; and gawk from GNU.

Author bio and support

Me!

Ruben Schade is a technical writer and infrastructure architect in Sydney, Australia who refers to himself in the third person. Hi!

The site is powered by Hugo, FreeBSD, and OpenZFS on OrionVM, everyone’s favourite bespoke cloud infrastructure provider.

If you found this post helpful or entertaining, you can shout me a coffee or send a comment. Thanks ☺️.