我正在尝试执行一个添加到我的文件的命令:
当前输入文件的名称 + 逗号数小于 5 的行索引 + 跨行的逗号数。
I got:
awk -F"," '{ if(NF > 5) printf("Filename: %d Index: %d Number of commas : %d\n",FILENAME,NR, NF-1); }' dsc* >> filename.csv
输出是:
Filename: 0 Index: 68520 Number of commas : 6
索引和逗号似乎工作正常,但是文件名呢?
我究竟做错了什么?
它应该是例如:
Filename: dscabc.txt Index: 68520 Number of commas : 6
Filename: dscabc1.txt Index: 123 Number of commas : 6
FILENAME
是一个字符串,而不是数字。使用%s
:
awk -F"," '{ if(NF > 5) printf("Filename: %s Index: %d Number of commas : %d\n",FILENAME,NR, NF-1); }' dsc* >> filename.csv
从以下部分man awk
讨论的是printf
:
%d, %i A decimal number (the integer part).
%s A character string.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)