如何从unix中的巨大文本文件中获取一些特定的行? [英] How to get some specific lines from huge text file in unix?

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

问题描述

我使用基于分隔文本文件的导入系统.使用的文件有时几乎有 2 Gb 大,我必须检查该文件中的一些行.所以我想知道如何输出(在另一个文件上,或者只是在屏幕上)特定值的行?例如.行号 1010123、1002451、994123 等,与源文件中的行号完全一样吗?

I use importing systems based on delimited text files. The files used can sometimes be almost 2 Gb big and I have to check some lines from that file. So I want to know how can I output (on another file, or just on screen) the lines of specific value? E.g. line number 1010123, 1002451, 994123, etc., exactly as they are in the source file?

推荐答案

要打印行 N,请使用:

sed 'Nq;d' file

打印多行(假设它们按升序排列)例如994123、1002451、1010123:

To print multiple lines (assuming they are in ascending order) e.g. 994123, 1002451, 1010123:

sed '994123p;1002451p;1010123q;d' file

最后一行号后的q告诉sed在到达第1010123行时退出,而不是通过循环我们不感兴趣的剩余行来浪费时间in.这就是为什么它对大文件很有效.

The q after the last line number tells sed to quit when it reaches the 1010123th line, instead of wasting time by looping over the remaining lines that we are not interested in. That is why it is efficient on large files.

这篇关于如何从unix中的巨大文本文件中获取一些特定的行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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