为什么我的Awk命令在没有for循环的情况下过滤文本,而在添加for循环时却不过滤文本?

为什么我的Awk命令在没有for循环的情况下过滤文本,而在添加for循环时却不过滤文本?,awk,Awk,我尝试过滤“5”并使用“for”打印3次 这是不带的用于循环的命令: awk -v OFS='"' -v FS='Name": "' 'match($2, /5"/){print $0}' sumacomando 这是带有for循环的命令: awk -v OFS='"' -v FS='Name": "' '{for(i=1;i<=3;i++) {match($2, /5"/); {print $0}}}' sumacomando awk-vofs='''-vfs='Name:“'{

我尝试过滤“5”并使用“for”打印3次

这是不带
的用于
循环的命令:

awk -v OFS='"' -v FS='Name": "'  'match($2, /5"/){print $0}' sumacomando
这是带有
for
循环的命令:

awk -v OFS='"' -v FS='Name": "'  '{for(i=1;i<=3;i++) {match($2, /5"/); {print $0}}}' sumacomando

awk-vofs='''-vfs='Name:“'{for(i=1;i我已经告诉过你如何处理这样的问题。请参阅,并在回答中添加一行内容:

f["fechaName"]==5{for (i=1;i<=3;i++) print}

f[“fechaName”]==5{for(i=1;iShort?我甚至删除了空格:

$ awk '$2~/^"5"/{for(;++i<=3;)print}' file
"fechaName": "5","xxxxx": "John",   "xxxxx": "John",    "firstName": "beto2", "xxxxx": "John","lastName": "444", "xxxxx": "John","xxxxx": "John",
"fechaName": "5","xxxxx": "John",   "xxxxx": "John",    "firstName": "beto2", "xxxxx": "John","lastName": "444", "xxxxx": "John","xxxxx": "John",
"fechaName": "5","xxxxx": "John",   "xxxxx": "John",    "firstName": "beto2", "xxxxx": "John","lastName": "444", "xxxxx": "John","xxxxx": "John",

$awk'$2~/^“5/{for(;++iif)如果输入更改为NDJSON(非常接近它)然后你可以使用jsonfilter和jsonmap之类的工具。也许你应该停止创造性地设置FS。最好遵循大家已经同意的最佳实践和习惯用法。你一直在问同一个问题,但没有修改提供的答案。嗨,我明白,但我需要更简短的解决方案,然后编辑你的问题to包括这一极其重要的要求,以及解决方案必须有多少个字符才能满足的声明,以及为什么要考虑这一点。如果您只需要一些简短的内容来产生输出,那么您可以使用
grep-h''5“'file
。我把我的代码放在这里,我需要知道为什么不能像预期的那样工作awk-vofs='''''-vfs='Name:“''{for(i=1;iawk-vofs=''''''-vfs='Name:''{for(i=1;iSerly-请编辑您的问题,以清楚地说明您的实际问题是什么,是如何明智地做您想要做的事情,还是如何简单地做您想要做的事情,或者只是帮助调试脚本或其他东西。现在还不清楚您在寻求什么帮助。
f["fechaName"]==5{for (i=1;i<=3;i++) print}
$ cat tst.awk
BEGIN {
    FPAT = "([^,]*)|(\"[^\"]+\")"
    OFS = ","
}
{
    delete f
    for (i=1; i<=NF; i++) {
        split($i,t,/[[:space:]":]+/)
        f[t[2]] = t[3]
    }
}
f["fechaName"]==5 { for (i=1;i<=3;i++) print }

$ awk -f tst.awk file
"fechaName": "5","xxxxx": "John",   "xxxxx": "John",    "firstName": "beto2", "xxxxx": "John","lastName": "444", "xxxxx": "John","xxxxx": "John",
"fechaName": "5","xxxxx": "John",   "xxxxx": "John",    "firstName": "beto2", "xxxxx": "John","lastName": "444", "xxxxx": "John","xxxxx": "John",
"fechaName": "5","xxxxx": "John",   "xxxxx": "John",    "firstName": "beto2", "xxxxx": "John","lastName": "444", "xxxxx": "John","xxxxx": "John",
{for(i=1;i<=3;i++) {match($2, /5"/)  ;{  print $0}}}
match($2, /5"/) { for(i=1;i<=3;i++) print }
$ awk '$2~/^"5"/{for(;++i<=3;)print}' file
"fechaName": "5","xxxxx": "John",   "xxxxx": "John",    "firstName": "beto2", "xxxxx": "John","lastName": "444", "xxxxx": "John","xxxxx": "John",
"fechaName": "5","xxxxx": "John",   "xxxxx": "John",    "firstName": "beto2", "xxxxx": "John","lastName": "444", "xxxxx": "John","xxxxx": "John",
"fechaName": "5","xxxxx": "John",   "xxxxx": "John",    "firstName": "beto2", "xxxxx": "John","lastName": "444", "xxxxx": "John","xxxxx": "John",