awk:awk_field_separator_delimiters
This is an old revision of the document!
Table of Contents
AWK - AWK Field Separator Delimiters
Assuming a file exists 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 Field Separator 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
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}' /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 specify the output delimiter.
awk/awk_field_separator_delimiters.1588635559.txt.gz · Last modified: 2020/07/15 09:30 (external edit)