Reputation: 6100
How do I open just a subset of very large file using vi
Upvotes: 2
Views: 1255
Reputation: 5347
In complement, I wrote a small script to edit/view a file slice (vimslice).
#!/usr/bin/perl -s
my $file=shift or die("Error:
usage: $0 [-n] file startline [endline]
-n don't save changes in file.out\n");
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});}
After chmod and install it do
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
Upvotes: 1
Reputation: 196566
I would not use Vim, here, because of performance issues. A pager would be better fit for the job.
Open last 10000 lines
$ tail -n 10000 filename | less
Open 10000, 20000 lines
$ sed -n 10000,20000p filename | less
Anyway, you can replace less
with vim -
if you really want Vim.
Upvotes: 4