且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

AWK-语法错误:文件意外结束

更新时间:2022-02-26 22:49:54

正确的方法是:

awk -F'"' -v OFS='' '
    FNR==1 { close(out); out="allan-"FILENAME }
    { for (i=2; i<=NF; i+=2) gsub(/,/, "", $i); print > out }
' /home/whoisdat/all-data/*

当我们开始读取下一个输入文件时,我们将关闭前一个输出文件,以避免出现打开文件过多"的情况.当超过10个左右的限制时,大多数awks都会产生错误(可以处理许多打开文件的GNU awk会变慢,这也是不希望的),我们只在那儿关闭它,而不是对每个输入行进行一次处理,以避免每行输入一次打开和关闭输出文件的性能显着提高.

We close the previous output file when we start reading the next input file to avoid a "too many open files" error from most awks when we get past a limit of a dozen or so (GNU awk which can handle many open files suffers a slowdown instead which is also undesirable), and we only close it there instead of once per input line processed to avoid the significant performance hit of opening and closing output files once per input line.

以上假设您未在/home/whoisdat/all-data/下运行命令,因此在脚本运行时在/home/whoisdat/all-data/中创建allan- *文件.

The above assumes you aren't running the command under /home/whoisdat/all-data/ and so creating allan-* files in /home/whoisdat/all-data/ while the script is running.