Pages

mardi 20 juillet 2010

Build-in variables in AWK Bash

Built-in variables

Awk's built-in variables include the field variables: $1, $2, $3, and so on ($0 is the entire line). They give the text or values in the individual text fields in a line.

There are a number of other variables:

* NR: Keeps a current count of the number of input lines.
* NF: Keeps a count of the number of fields in an input line. The last field in the input line can be designated by $NF.
* FILENAME: Contains the name of the current input file.
* FS: Contains the "field separator" character used to divide fields on the input line. The default is "white space", meaning space and tab characters. FS can be reassigned to another character to change the field separator.
* RS: Stores the current "record separator" character. Since, by default, an input line is the input record, the default record separator character is a "newline".
* OFS: Stores the "output field separator", which separates the fields when Awk prints them. The default is a "space" character.
* ORS: Stores the "output record separator", which separates the output lines when Awk prints them. The default is a "newline" character.
* OFMT: Stores the format for numeric output. The default format is "%.6g".

useful link : http://en.wikipedia.org/wiki/AWK

Aucun commentaire:

Enregistrer un commentaire