How to set a field separator to an empty string?

In awk manual states that both -v FSand -Fare equivalent ways of setting the field delimiter.

GNU Awk User Manual → 4.5.4 Configuring FS from the Command Line :

FS can be installed on the command line. The `-F 'argument is used for this.

(...)

The value used for the `-F 'argument is treated exactly like assignments to the FS built-in variable.

However, I noticed that there is a difference, if we set it to an empty string, this is not the same. Tested on mine GNU Awk 4.1.1.

It works:

$ awk -F, '{print $2}' <<< "a,b,c"
b
$ awk -v FS=, '{print $2}' <<< "a,b,c"
b

But this is not so:

$ awk -F="" '{print $2}' <<< "abc"
                                      # $1 contains abc
$ awk -v FS="" '{print $2}' <<< "abc"
b

Why? Is it because setting FSfor empty is gawkspecific?

+2
2

, :

$ awk -F '' '{print $2}' <<< "abc"
b

GNU awk ( 3.0.4 4.1.1) mawk 1.2

, -F '' !

+4

? , FS gawk?

, , , FS. awk , . awk OS/X .

awk: field separator FS is empty

FS awk.

+3

Source: https://habr.com/ru/post/1694911/


All Articles