Was this helpful?
Field Variables
Field variables represent the fields of the current line.
A variable assigned the string of the entire input line
$1, $2,...
A variable assigned the string value of the 1st, 2nd, and successive fields split from the input line at the separator.
As each input line is read, it is split into fields using the values of the IFS built-in variable as the field separator. Each field in the input line may be referenced by its position, $1, $2, and so on. The built-in variable NF contains the number of fields split from the current input line. References to non-existent fields (i.e., fields after NF) produce the null-string.
In addition, a group/range of characters within a field variable can be accessed by specifying the position in parenthesis following the field variable. The position of the first character in a field variable is 1; the second character is position 2, and so on. To specify a group/range of characters, the beginning and ending positions of the characters should be included within the parenthesis. This is true even if there is only one character in the range. The beginning and ending positions should be separated by one space.
$0 (9 9)
this references the 9th position of the current input line
$0 (3 23)
this references the 3rd through 23rd positions of the current input line
$3 (2 5)
this references the 2nd through the 5th input line
Last modified date: 01/25/2022