awk:awk_fields
This is an old revision of the document!
AWK - AWK Fields
Understanding Fields.
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
Issue the following command:
awk '{print $1,$2,$3,$4,$5}' test.txt
which will display something like:
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
- AWK has read each field in the file into the variables $1, $2, $3, etc.
- Each field is split by a field separator, which by default is a space or comma.
- As can be seen, it does not matter how many spaces separate each field in the input file.
NOTE: As AWK reads the input, the entire record is assigned to the variable $0.
awk/awk_fields.1588633197.txt.gz · Last modified: 2020/07/15 09:30 (external edit)