The Fields

What Becomes a Field...


When awk reads a line from the input file into a record. It seperates that record into fields based on a delimeter stored in the built in variable FS (Field Seperator), the default is a space, but the Field Seperator could be any character or regex. The space is special. When FS is a space, awk strips leading and trailing whitespace from the record. Then processes the fields.

CREATED 2016-05-28 14:26:02.0

00-24-EA

UPDATED 2016-05-28 14:26:15.0

Built in Variables for Fields...


Name Descrption
FS Field Seperator. The value awk uses to seperate a record into fields. The default is any combonation of spaces or tabs.
NF The Number of Fields in the current record.

CREATED 2016-06-14 04:50:28.0

00-24-F1

UPDATED 2016-06-14 04:50:51.0

Field Seperator (FS)...


The Field Seperator (FS) can be any character. The default is awk whitespace i.e. any combonation of spaces or tabs. Other whitespace such as form feed or new line is not white space in awk.

CREATED 2016-06-14 04:58:42.0

00-24-F2

UPDATED 2016-06-14 04:58:58.0

Referencing Fields...


awk creates numeric variables that represent the fields of the record read from the input file. They are numbered from left to right. They can be referenced by the numeric value of their position by preceeding it with a $ sign. For example $1 would hold the first field, $2 the second and so on. $0 holds all the fields in record.

So let us put this in practice... on a linux system if I issue the command:

ls -l | awk '{print $9}'

Then I would get a list of file names for the current directory.

Backups Docs Documents Downloads Funny home HTML learning lib Projects Video










CREATED 2016-05-28 14:29:54.0

00-24-EB

UPDATED 2016-05-28 14:30:05.0

Knowledge

L
I
N
K
S

DBID: db.wam

Page Server: Ithica

©2012 Leistware Data Systems

      Hello anonymous