Full Line Fields (The GNU Awk User’s Guide)
Next: Field Splitting Summary, Previous: Command Line Field Separator, Up: Field Separators [Contents][Index]
4.5.5 Making the Full Line Be a Single Field
Occasionally, it’s useful to treat the whole input line as a single field. This can be done easily and portably simply by setting FS
to "\n"
(a newline):22
awk -F'\n' 'program' files …
When you do this, $1
is the same as $0
.
Changing
According to the POSIX standard,
However, many older implementations of sed 1q /etc/passwd | awk '{ FS = ":" ; print $1 }' which usually prints: root on an incorrect implementation of root:x:0:0:Root:/: (The |
Footnotes
(22)
Thanks to Andrew Schorr for this tip.
(23)
The sed
utility is a “stream editor.” Its behavior is also defined by the POSIX standard.