问题描述
我正在编写 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 文件.我试图在记事本、excel 中打开这个文件,但似乎没有软件会打开它.
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 和 unxutils 包都有 tail
实用程序.
On Windows, there are gnuwin32 and unxutils packages both have tail
utility.
这篇关于如何从 Perl 中的文件末尾读取行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!