Custom awk delimiters
SoftwareIn 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.