Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
AWK
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
=== Built-in variables === AWK's built-in variables include the field variables: $1, $2, $3, and so on ($0 represents the entire record). They hold the text or values in the individual text-fields in a record. Other variables include: * <code>NR</code>: Number of Records. Keeps a current count of the number of input records read so far from all data files. It starts at zero, but is never automatically reset to zero.<ref name="GNU.org Records">{{Cite book|chapter-url=https://www.gnu.org/software/gawk/manual/html_node/Records.html#index-FNR-variable|chapter=Records|url=https://www.gnu.org/software/gawk/manual/|title=GAWK: Effective AWK Programming: A Userβs Guide for GNU Awk|date=September 2024|edition=5.3|access-date=2025-01-24}}</ref> * <code>FNR</code>: File Number of Records. Keeps a current count of the number of input records read so far ''in the current file.'' This variable is automatically reset to zero each time a new file is started.<ref name="GNU.org Records" /> * <code>NF</code>: Number of Fields. Contains the number of fields in the current input record. The last field in the input record can be designated by $NF, the 2nd-to-last field by $(NF-1), the 3rd-to-last field by $(NF-2), etc. * <code>FILENAME</code>: Contains the name of the current input-file. * <code>FS</code>: Field Separator. Contains the "field separator" used to divide fields in the input record. The default, "white space", allows any sequence of space and tab characters. FS can be reassigned with another character or character sequence to change the field separator. * <code>RS</code>: Record Separator. Stores the current "record separator" character. Since, by default, an input line is the input record, the default record separator character is a "newline". * <code>OFS</code>: Output Field Separator. Stores the "output field separator", which separates the fields when awk prints them. The default is a "space" character. * <code>ORS</code>: Output Record Separator. Stores the "output record separator", which separates the output records when awk prints them. The default is a "newline" character. * <code>OFMT</code>: Output Format. Stores the format for numeric output. The default format is "%.6g".
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)