Because:
Normally, any number of blanks separate fields. In order to set the
field separator to a single blank, use the -F option with a value of
[ ]
. If a field separator of t
is specified, awk treats it as if
\t
had been specified and uses <TAB> as the field separator. In order
to use a literal t
as the field separator, use the -F option with a
value of [t]
.
That's from the FreeBSD awk man page, and the utilities that come with macOS are usually some old FreeBSD versions or such.
$ printf 'foo\tbar\n' | awk -F t '{print NF-1}'
1
$ echo total | awk -F '[t]' '{print NF-1}'
2
In a way, that seems like a useful shorthand for files with tab-separated values, but what with other letters taken as-is, it's confusing. It only works like that with -F
, using -v FS=t
doesn't do it.
The feature is non-POSIX, as POSIX says that -F x
is the same as -v FS=x
. Most other awks I tested treated t
as the the literal letter (some versions of gawk, mawk and Busybox).
The version of awk that e.g. Debian has in the original-awk
package ("One True AWK" or "BWK awk" presumably from Brian W. Kernighan's initials) does support it, though, and at least Wikipedia seems to indicate that would be the same software FreeBSD uses. This one appears to be based on the version described in the 1988 book "The AWK Programming Language", but I'm not an expert on awk lineages and don't know if it has evolved significantly since then. That one is on github, but the documentation there doesn't seem to describe the feature. The special case can be seen in the code (where it's described as "a wart" in a comment).
You can get the same behaviour with GNU awk in BWK-awk compatibility mode, though.:
As a special case, in compatibility mode (see section Command-Line Options), if the argument to -F is ‘t’, then FS is set to the TAB character. If you type ‘-F\t’ at the shell, without any quotes, the ‘\’ gets deleted, so awk figures that you really want your fields to be separated with TABs and not ‘t’s.