使用awk计数记录数 [英] Using awk to count number of records

查看:557
本文介绍了使用awk计数记录数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过awk计算表中的所有记录,但是NR打印所有记录的记录号而不是总数.我什至尝试过:

I want to count all the records in a table through awk but NR prints record nos of all records not the total count. I even tried:

NF==4,count++{print count}

但是它不能正常工作 我该如何通过awk做到这一点?

But its not working properly How can I do it through awk?

推荐答案

请下次显示文件示例以及该文件的用途(显示所需的输出).只是猜到你想要什么,

Please show a sample of your file and what you want to do with it (show the desired output ) next time. Just guessing what you want,

awk 'NF==4{count++} END {print count}' file

记录总数用NR表示.

awk 'END{print NR}' file1 file2

当前记录的总数用FNR表示.

the total number of records currently is denoted by FNR.

awk 'END{print FNR}' file

这篇关于使用awk计数记录数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆