The Record

How awk Reads Input...


When awk reads from the input source it relies on the value stored in the built in variable RS (Record Seperator). The default for RS is a new line. awk takes the input from the current point in the file up to the record seperator and creates a record from that data.

CREATED 2016-05-27 13:34:16.0

00-24-E8

UPDATED 2016-06-07 16:34:52.0

Built in Variables for Records...


Name Descrption
RS Record Seperator. The value awk uses to seperate input into recrods. A new line by default
RT Record Terminator.
FNR The Number of Records from this input stream or File. This value will be reset when input streams or files change.
NR The Number of Records read from all input streams. This value does not automatically get reset.

CREATED 2016-06-06 14:30:42.0

00-24-EC

UPDATED 2016-06-14 04:52:00.0

RS...


RS = ";"

The default value of RS is a new line. The value of RS can be changed with the assignment oporator. Example:

will cause awk to seperate records when it sees a semi-colon instead of a new line. However, the default value of RS has some advantages. When default RS is used awk automatically trims leading and trailing spaces from the record itself. This may be a plus unless they are needed.

CREATED 2016-06-07 16:40:24.0

00-24-ED

UPDATED 2016-06-07 16:40:29.0

RT...


RT (Recort Terminator) is what awk uses to terminate a record.

CREATED 2016-06-07 16:40:55.0

00-24-EE

UPDATED 2016-06-07 16:41:05.0

FNR...


The value of FNR is incremented for each record read. But FNR only pertains to the current input source. As the input source is changed e.g. multiple files on the command line, FNR is reset to zero.

CREATED 2016-06-07 16:42:04.0

00-24-EF

UPDATED 2016-06-07 16:42:09.0

NR...


NR (Number of Records) is the total number of records read from all input sources during the run of the program. Where FNR is reset when input sources change, NR is not automatically reset.

CREATED 2016-06-07 16:43:50.0

00-24-F0

UPDATED 2016-06-07 16:43:54.0

Knowledge

L
I
N
K
S

DBID: db.wam

Page Server: Ruger

©2012 Leistware Data Systems

      Hello anonymous