User Tools

Site Tools


awk:awk_field_separator_delimiters

This is an old revision of the document!


AWK - AWK Field Separator Delimiters

Assuming a file exists, test.txt, with the following contents:

10   Peter     Terence   Roux        45
11   Virginia  Genevive  Roux        45
12   Felix     Devon     Roux         5
13   David     Bruce     Stevenson   48
14   Bob       James     Smith       16
48   Adam      Winter    Ridley      23

Specifying Input Field Separator Delimiter

To set an alternative field delimiter, issue the following command:

awk '{FS=":"}{print $2,$4}' test.txt

or

awk -F: '{print $2,$4}' test.txt

NOTE: This is useful when a space is not being used as the delimiter in the input file.


Specifying Output Field Separator Delimiter

To set an alternative field delimiter for the output, issue the following command:

awk '{OFS="-"}{print $2,$4}' test.txt

which will display something like:

Peter-Roux
Virginia-Roux
Felix-Roux
David-Stevenson
Bob-Smith
Adam-Ridley

NOTE: The OFS variable is used to specify the output delimiter.

awk/awk_field_separator_delimiters.1609946806.txt.gz · Last modified: 2021/01/06 15:26 by peter

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki