如何更改awk中的动态模式?

how to change a dynamic pattern in awk?

数据类似于

"1||2""3""2||3""5""4||3""6""43""4||4||3""4||3", 43 ,"4||3""43""3||4||4||3"

我自己试过了

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

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

但问题是它给我的输出像

$ gawk -f prog4.awk data1.txt
NF =  18
 = <"1||2">
 = <"3">
 = <"2||3">
 = <"5">
 = <"4||3">
 = <"6">
 = <"43">
 = <"4||4||3">
 = <"4||3">
 = <,>
 = < >
 = <4>
 = <3>
 = < >
 = <,>
 = <"4||3">
 = <"43">
 = <"3||4||4||3">
>

如您所见,每个角色都被占用了 10 到 15 美元。帮助赞赏。

让我们尝试以不同的方式解决这个问题 - 如果以下内容不是您要找的内容,请告诉我们它与您想要的输出有何不同以及原因:

$ cat tst.awk
BEGIN { FPAT="\"[^\"]+\"" }
{
    for (i=1; i<=NF; i++) {
        print i, "<" $i ">"
    }
}
$ 
$ gawk -f tst.awk file
1 <"1||2">
2 <"3">
3 <"2||3">
4 <"5">
5 <"4||3">
6 <"6">
7 <"43">
8 <"4||4||3">
9 <"4||3">
10 <"4||3">
11 <"43">
12 <"3||4||4||3">