有没有办法让awk返回符合字段分隔符标准的字段数?比如说,我的文件包含
a b c d
Run Code Online (Sandbox Code Playgroud)
所以,awk --field-separator=" " | <something>应该返回4
Dou*_*yer 53
该NF变量设置为输入记录中的字段总数.所以:
echo "a b c d" | awk --field-separator=" " "{ print NF }"
会显示
4
但请注意:
echo -e "a b c d\na b" | awk --field-separator=" " "{ print NF }"
将显示:
4 2
希望这会有所帮助,并且很开心