User Tools

Site Tools


awk:awk_field_separator_delimiters

This is an old revision of the document!


AWK - AWK Field Separator Delimiters

Specifying Field Seperator Delimiter

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

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

or

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

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}' /sharewiz/awk/test.txt

which will display something like:

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

The OFS variable is used to specific the output delimiter.

awk/awk_field_separator_delimiters.1588635444.txt.gz · Last modified: 2020/07/15 09:30 (external edit)

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki