Reputation: 1063
In this context, how does the specified field separator work?
awk -F\' '{print "conn kill "$2"\nrepair mailbox "$2" repair=1"}'
Upvotes: 0
Views: 155
Reputation: 92442
AWK processes a file line by line. And each line is separated into fields, that you can then access with the dollar variables $1
...$9
($0
is the whole line, IIRC). By default, the line is split into fields by using separating on whitespace, but you can specify on which character to split by using the -F
command line option or the FS
variable.
So in your case, the field separator is set to a single quote ('
). An input line like foo'bar'baz
will thus set $1 == "foo"
, $2 == "bar"
and $3 == "baz"
.
Upvotes: 1
Reputation: 455460
-F\'
is using the single quote '
as the field separator.
Also the '
is being escaped by preceding it with a \
so that awk does not think of the '
as the beginning of the action part.
Alternatively you can enclose the '
in double quotes:
$ echo "foo'bar'baz" | awk -F\' '{print $1}'
foo
$ echo "foo'bar'baz" | awk -F"'" '{print $1}'
foo
Upvotes: 2