Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typo3/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
AWK合并行累加器不工作_Awk - Fatal编程技术网

AWK合并行累加器不工作

AWK合并行累加器不工作,awk,Awk,下面是一条分为两行的单记录,在字段3后面有一个嵌入的换行符(空行是嵌入的换行符) 算法是,如果记录中的字段少于4个,则继续合并后续行,直到有4个字段,然后输出记录 我有一个awk代码,应该可以做到这一点。2例 案例1 > If the number of fields in the current line plus the accumulated > number of fields = 4 then if there were no previous fields &g

下面是一条分为两行的单记录,在字段3后面有一个嵌入的换行符(空行是嵌入的换行符)

算法是,如果记录中的字段少于4个,则继续合并后续行,直到有4个字段,然后输出记录

我有一个awk代码,应该可以做到这一点。2例

案例1

> If the number of fields in the current line plus the accumulated
> number of fields = 4 then     if there were no previous fields 
>        print current line      else 
>       print previously accumulated line plus current line
案例2将当前行附加到先前累积的行中

BEGIN {
  FS=","
  flds=4
  prevF=0
}
flds == NF + prevF {
                    print (prevF==0) ?  $0 :  prevLine $0
                    prevF=0
                    prevLine=""
                    next
                   }
{prevLine = (prevF==0) ? $0 FS : prevLine $0
 prevF = prevF + NF}
算法足够简单。当我对得到的数据片段运行它时

,mnohi,9,ghi
而不是第二行钉在第一行的末尾


我感兴趣的是理解为什么代码按原样运行以及在awk解决方案中

不清楚,请在您的帖子中的代码标签中添加适当的示例输入和预期输出,然后让我们知道。听起来您的输入文件包含控件Ms,请使用
cat-v
查看它们,然后使用dos2unix或类似工具删除它们,然后告诉我们您是否仍然存在问题。就是这样。谢谢
,mnohi,9,ghi