如何使用vi只打开非常大的文件的子集



如何使用vi 只打开非常大的文件的子集

  1. 使用vi打开最后10000行
  2. 使用vi打开10000、20000条线路

由于性能问题,我不会在这里使用Vim。寻呼机更适合这份工作。

  1. 打开最后10000行

    $ tail -n 10000 filename | less
    
  2. 打开10000、20000行

    $ sed -n 10000,20000p filename | less
    

无论如何,如果真的想要Vim,可以用vim -替换less

作为补充,我编写了一个小脚本来编辑/查看文件切片(vimslice)。

#!/usr/bin/perl -s
my $file=shift or die("Error:
 usage: $0 [-n] file startline [endline]
   -n      don't save changes in file.outn");
my $sl = shift || 1;
my $el = shift || ($sl+1000);
system("sed -n -e '$sl,$el p' $file > $file.$$");
system("vi $file.$$");
if(not $n){
  system(qq{awk '(NR==$el)          {system("cat $file.$$")}
                  NR==$sl,NR==($el) {next}
                                    {print}' $file> $file.out});}

chmod和安装后做

vimslice bigfile 10000 20000      
     ...  edit the slice, replace and save in "bigfile.out" 
vimslice -n bigfile 10000 20000        
     ...  just view the slice
vimslice bigfile 10000
     ... the same as vimslice bigfile 10000 10000+1000

最新更新