Christian Mayne

Spliting strings with awk / nawk

by | Dec 21, 2011 | Work | 0 comments

I mainly use nawk to extract elements from a string where I know the position (eg to get just the filenames when running a grep and I’m just too lazy to remember the correct grep syntax).

so, to extract field number x from strings in where the field separator (FS) is y:

$ nawk '{ FS="y"; print $x }'
Christian Mayne

Christian Mayne

Web developer and internet consultant, Anglo-Concertina player, fan of traditional music and record collector.