- 论坛徽章:
- 0
|
主要问题可能是ls *.dat及xargs两个命令命令行缓冲有限制,文件数量较大时不能在命令行用通配符,也不要用xargs.
下面代码调试通过,应该符合楼主要求:
- ls | awk -F'[_.]' '
- BEGIN{countf=eoff=0;}
- $2+0>=201009080000 && $2+0 <=201009250000 && $3=="dat" && NF==3{
- countf++;FS="[ \t]+";fname=$0;
- while (1==getline<fname){
- if($2~"EOF"){
- eoff++;break;
- }
- };
- close(fname);
- FS="[_.]";
- }
- END{
- print "\nTotal:,",countf,"EOF:",eoff;
- }'
复制代码
下面带调试语句的(去掉#)脚本,并先生成调试数据后测试:
- echo "1
- 2 EOF">0_200009080900.dat
- echo "2" >1_200009080900.dat
- echo "1
- 2
- 3
- 3 EOF">2_201009080010.dat
- echo "4" >3_201009080030.dat
- echo "4" >4_201009080020.dat
- echo "4" >5_201109080020.dat
- ls | awk -F'[_.]' '
- BEGIN{countf=eoff=0;}
- #{print "#0",NR,$0}
- $2+0>=201009080000 && $2+0 <=201009250000 && $3=="dat" && NF==3{
- countf++;
- FS="[ \t]+";
- fname=$0;
- # print "#1",$0,countf,eoff,fname;
- while (1==getline<fname){
- # print "#2",$0,countf,eoff,fname;
- if($2~"EOF"){
- eoff++;
- # print "#3",$0,countf,eoff,fname;
- break;
- }
- };
- close(fname);
- FS="[_.]";
- }
- END{
- print "\nTotal:,",countf,"EOF:",eoff;
- }'
复制代码 |
|