Text Editor – How to Open Large XML File

text-editorxml

I am trying to open a relatively large XML file (50mb) but my Mac just won't open it: No errors though, just been waiting for almost 10 minutes but nothing happens.

Tried using TextEditor, Xcode

Any other suggestions?

Best Answer

Depending on the source of the file, you may wish to investigate its contents in other ways than just opening it (double clicking). For this, you should use the command line.

Some suggested starting points (where "whatever.xml" is the name of the file):

file whatever.xml

This will tell you what type the file is. Not by file extension, but by actual examination of the contents.

head whatever.xml

This will show you the first ten lines of the file. However, be warned: It is possible to have an entire 50 MB XML file consisting of a single line. Press Ctrl-C to stop if it starts spewing garbage. (Yes, Control C, not Command-C.)

To just view the file without even the possibility of editing it:

less whatever.xml

If the file does consist of very long lines, for reading it, you could force periodic line wraps (formatting):

fmt whatever.xml | less

But actually, less will wrap the lines by default unless you tell it not to. For no wrapping of lines (so you can use sideways arrow keys to scroll):

less -S whatever.xml

It is a good probability that one of these commands will disclose a problem with the file.

Related Question