Linux下打开大文件方法探究

来源:互联网 发布:免费的数据挖掘软件 编辑:程序博客网 时间:2024/06/07 08:11
从网上下载了一个语料,解压后有16G,在Windows下使用了编辑器打开会提示内存超出限制。因此将文件放到Linux下去打开,分别尝试了以下几种方法:

vim

vim 会一次性把文件load到内存。

这是用vim打开后的top图
top图

PS:因为用的是机械硬盘,wa很高。

这跟windows的一次性加载是一样的,估计一时半会儿是不能加载完成了。

网上也有说通过一个LargeFile 插件可以让vim实现对大文件的快速编辑。但是LargeFile只是在打开大文件时,关掉vim的事件、回退、语法高亮等功能(its just an autocmd that disables certain features of vim in the interests of speed. ),并不能解决vim一次性加载文件到内存的问题。

因此,使用vim的方案不可取。

cat

cat stands for “catenate.” It reads data from files, and outputs their contents. It is the simplest way to display the contents of a file at the command line.

cat会一次性输出文件的所有内容,用cat来读取16G的文件,你只能看到在屏幕上不断打印的内容,无法阅读。

head/tail

head makes it easy to output the first part of files.

如果只看文件的前一部分,用 head -n 就是最佳选择。

tail outputs the last part, or “tail”, of files.

与head一样,打开的速度非常快。
因为只需要定位到文件的尾部,再读取即可。

less/more

less does not have to read the entire input file before starting, so with large input files it starts up faster than text editors like vi.

more is a filter for paging through text one screen at a time. It does not provide as many options or enhancements as less, but is nevertheless quite useful and simple to use.

less/more并不需要加载全部文件,因此在打开大文件的时候,less/more具有优势。

grep/sed/awk

这些命令不会一次性load整个文件,而是一部分一部分读取到buff处理。

0 0
原创粉丝点击