gawk FPAT不会覆盖FS

时间:2016-11-04 10:48:35

标签: shell awk gawk

我有一个格式为:

的csv文件
"a b c","d","e","f",
"bla","bla","bli","fff"

官方GNU站点给出here的FPAT规定“为FPAT分配值会覆盖使用FS和FIELDWIDTHS进行字段拆分”。 但是,我尝试了他们的代码:

BEGIN {
    FPAT = "([^,]+)|(\"[^\"]+\")"
}

{
    print "NF = ", NF
    for (i = 1; i <= NF; i++) {
    printf("$%d = <%s>\n", i, $i)
    }
}

用这个:

echo 'Robbins,Arnold,"1234 A Pretty Street, NE",MyTown,MyState,12345-6789,USA' | gawk -f bin/test.awk

这是预期的结果:

NF =  5
$1 = <Robbins,Arnold,"1234>
$2 = <A>
$3 = <Pretty>
$4 = <Street,>
$5 = <NE",MyTown,MyState,12345-6789,USA>

我认为默认的FS(空格)没有被覆盖。 好吗?

0 个答案:

没有答案