上QQ阅读APP看书,第一时间看更新
The -F option – field separator
By default, fields in the input record are separated by any number of spaces or tabs. This behavior can be altered by using the -F option or the FS variable. The value of the field separator can be either a single character or a regular expression. It controls the way AWK splits an input record into fields:
-Ffs
--field-separator
In the next example, we illustrate the use of the -F option. Here we used the -F to print the list of usernames that has been assigned to the bash shell from the /etc/passwd file. This file contains userdetails separated by a colon (:):
$ awk -F: '/bash/ { print $1 }' /etc/passwd
This can also be performed as follows:
$ awk --field-separator=: '/bash/ { print $1 }' /etc/passwd
The output on execution of this code is as follows:
at
bin
daemon
ftp
games
lp
man
news
nobody
...................
...................