I tried opening a huge (~2GB) file in VIM but it choked. I don't actually need to edit the file, just jump around efficiently.
How can I go about working with very large files in VIM?
I tried opening a huge (~2GB) file in VIM but it choked. I don't actually need to edit the file, just jump around efficiently.
How can I go about working with very large files in VIM?
Since you don't need to actually edit the file:
view
(orvim -R
) should work reasonably well on large files.more
orless
For huge one-liners (prints characters from
1
to99
):This has been a recurring question for many years. (The numbers keep changing, but the concept is the same: how do I view or edit files that are larger than memory?)
Obviously
more
orless
are good approaches to merely reading the files ---less
even offersvi
like keybindings for scrolling and searching.A Freshmeat search on "large files" suggests that two editors would be particularly suited to your needs.
One would be: lfhex ... a large file hex editor (which depends on Qt). That one, obviously, entails using a GUI.
Another would seem to be suited to console use: hed ... and it claims to have a
vim
-like interface (including anex
mode?).I'm sure I've seen other editors for Linux/UNIX that were able to page through files without loading their entirety into memory. However, I don't recall any of their names. I'm making this response a "wiki" entry to encourage others to add their links to such editors. (Yes, I am familiar with ways to work around the issue using
split
andcat
; but I'm thinking of editors, especially console/curses editors which can dispense with that and save us the time/latencies and disk space overhead that such approaches entail).emacs works very well with files into the 100's of megabytes, I've used it on log files without too much trouble.
But generally when I have some kind of analysis task, I find writing a perl script a better choice.
this is old but, use nano, vim or gvim
I had a 12GB file to edit today. The vim LargeFile plugin did not work for me. It still used up all my memory and then printed an error message :-(. I could not use hexedit for either, as it cannot insert anything, just overwrite. Here is an alternative approach:
You split the file, edit the parts and then recombine it. You still need twice the disk space though.
Grep for something surrounding the line you would like to edit:
Extract that range of the file. Say the lines you want to edit are at line 4 and 5. Then do:
-n
option is required to suppress the default behaviour of sed to print everything4,5p
prints lines 4 and 55q
aborts sed after processing line 5Edit
SMALLPART
using your favourite editor.Combine the file:
HUGEFILE.new
will now be your edited file, you can delete the originalHUGEFILE
.