如何在Perl中读取文件末尾的行? [英] How can I read lines from the end of file in Perl?

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

问题描述

我正在使用Perl脚本来读取CSV文件并进行一些计算. CSV文件只有两列,如下所示.

I am working on a Perl script to read CSV file and do some calculations. CSV file has only two columns, something like below.

One Two
1.00 44.000
3.00 55.000

现在此CSV文件非常大,可以从10 MB到2GB.

Now this CSV file is very big ,can be from 10 MB to 2GB.

当前,我正在使用大小为700 MB的CSV文件.我试图在记事本中打开此文件,但是它似乎没有软件可以打开它.

Currently I am taking CSV file of size 700 MB. I tried to open this file in notepad, excel but it looks like no software is going to open it.

我想读取的可能是CSV文件中的最后1000行,并查看这些值. 我怎样才能做到这一点?我无法在记事本或任何其他程序中打开文件.

I want to read may be last 1000 lines from CSV file and see the values. How can I do that? I cannot open file in notepad or any other program.

如果我编写Perl脚本,则需要处理完整的文件以转到文件末尾,然后读取最后1000行.

If I write a Perl script then I need to process complete file to go to end of file and then read last 1000 lines.

有什么更好的办法吗?我是Perl的新手,任何建议将不胜感激.

Is there any better way to that? I am new to Perl and any suggestions will be appreciated.

我已经在网上搜索过,并且有一些脚本可用,例如 File::Tail ,但是我不知道它们将在Windows上运行吗?

I have searched net and there are some scripts available like File::Tail but I don't know they will work on windows ?

推荐答案

在* nix中,您可以使用tail命令.

In *nix, you can use the tail command.

tail -1000 yourfile | perl ...

那只会将最后1000行写到perl程序中.

That will write only the last 1000 lines to the perl program.

在Windows上,有 gnuwin32

On Windows, there are gnuwin32 and unxutils packages both have tail utility.

这篇关于如何在Perl中读取文件末尾的行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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