Pretty print XML on Linux Command Line BASH

It’s quite handy to indent XML when you need to read it with the human eye, but on a terminal it’s often not as easily readible.
Fortunatly there’s a command which’ll indent it so you can actually read it;
xmllint –format file.xml
This will show you how ugly it could be:
 

Screenshot Unformatted XML on terminal
Screenshot Unformatted XML on terminal

 
And behold the indented beauty of this little gem:
Screenshot indented XML on terminal
Screenshot indented XML on terminal

5 Replies to “Pretty print XML on Linux Command Line BASH”

    1. Hi Mohit,
      Not that i know of. The easiest way to get colored output is to copy the formatted XML to an editor and copy the colored output from there. For a couple of suggestions look for “colored xml formatting” on Google. (Also plenty of free options available)

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.