在巨大的文本文件(> 20G)的开头附近对行进行重新排序 [英] Reorder lines near the beginning of a huge text file (>20G)

查看:121
本文介绍了在巨大的文本文件(> 20G)的开头附近对行进行重新排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是vim用户,可以使用一些基本的awk或bash命令.现在,我有一个文本(vcf)文件,大小超过20G.我想要的是将69号行移至66号行以下:

I am a vim user and can use some basic awk or bash commands. Now I have a text (vcf) file with size more than 20G. What I wanted is to move the line #69 to below line#66:

$less huge.vcf
...
    66 ##contig=<ID=9,length=124595110>                                                                                                                                                       
    67 ##contig=<ID=X,length=171031299>                                                                                                                                                       
    68 ##contig=<ID=Y,length=91744698>                                                                                                                                                        
    69 ##contig=<ID=MT,length=16299>
...

我想要的是:

...
    66 ##contig=<ID=9,length=124595110>     
    67 ##contig=<ID=MT,length=16299>                                                                                                                                                  
    68 ##contig=<ID=X,length=171031299>                                                                                                                                                       
    69 ##contig=<ID=Y,length=91744698>                                                                                                                                                        
...

我尝试使用vim(已安装LargeFile插件)打开和编辑它,但仍然不能很好地工作.

I tried to open and edit it using vim (LargeFile plugin installed), but still not working very well.

推荐答案

简单的方法是将要编辑的部分从文件中复制出来,就地进行修改,然后再复制回去.

The easy approach is to copy the section you want to edit out of your file, modify it in-place, then copy it back in.

# extract the first hundred lines
head -n 100 huge.txt >start.txt

# modify that extracted subset
vim start.txt

# copy that section back into the beginning of larger file
dd if=start.txt of=huge.txt conv=notrunc

请注意,这仅在您的编辑不更改要修改的部分的大小的情况下才有效.也就是说-确保修改后的start.txt字节大小与以前完全相同.

Note that this only works if your edits don't change the size of the section being modified. That is to say -- make sure that start.txt has the exact same size in bytes after being modified that it had before.

这篇关于在巨大的文本文件(&gt; 20G)的开头附近对行进行重新排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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