如何计算符合条件的文件中的行? [英] How to count lines in a file that meet criteria?

查看:74
本文介绍了如何计算符合条件的文件中的行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下是具有访问网站的

访问者的IP地址和访问时间的内容文件。


68.122.69.241 | 1089822686


68.122.69.241 | 1089823630

68.122.69.241 | 1089823638


68.122.69.241 | 1089828547


第二列是时间的输出()


我需要一个脚本来计算此文件中时间戳为<的每一行br />
大于时间() - 3600 * 24。这将在过去24小时内给出

的访客数量。我还需要过去30天内的访客人数,并且每年需要
。我应该使用阵列吗?建议入门?


提前致谢。

Below are the contents file that has the IP address and time of visit of
visitors to a website.

68.122.69.241|1089822686

68.122.69.241|1089823630

68.122.69.241|1089823638

68.122.69.241|1089828547

The second column is the output of time()

I need a script to count each line in this file where the time stamp is
greater than time() - 3600*24. This will give number of visitors in the
last 24 hours. I also need number of visitors in the last 30 days, and
year. Should I use an array? Suggestions for getting started?

Thanks in advance.

推荐答案



"杰科" <无**** @ hotmail.com>在消息中写道

新闻:TD ******************* @ newssvr29.news.prodigy。 com ...

"deko" <no****@hotmail.com> wrote in message
news:TD*******************@newssvr29.news.prodigy. com...
以下是内容文件,其中包含访问网站的访问者的IP地址和访问时间。

68.122.69.241 | 1089822686

68.122.69.241 | 1089823630
68.122.69.241 | 1089823638

68.122.69.241 | 1089828547

第二栏是时间的输出()

我需要一个脚本来计算这个文件中的每一行,其中时间戳大于时间() - 3600 * 24。这将在过去24小时内为访客提供数量。我还需要过去30天内的访客数量,以及
年份。我应该使用阵列吗?关于入门的建议?

提前致谢。
Below are the contents file that has the IP address and time of visit of
visitors to a website.

68.122.69.241|1089822686

68.122.69.241|1089823630

68.122.69.241|1089823638

68.122.69.241|1089828547

The second column is the output of time()

I need a script to count each line in this file where the time stamp is
greater than time() - 3600*24. This will give number of visitors in the
last 24 hours. I also need number of visitors in the last 30 days, and
year. Should I use an array? Suggestions for getting started?

Thanks in advance.






f = file(" filename.txt");

foreach(
f=file("filename.txt");
foreach(


f as


这篇关于如何计算符合条件的文件中的行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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