4

There must be something on the lines of sed?

Normally in sed you type something like:

echo day | sed s/day/night/ 

the shell prints "night".

Is there something that can take a file (containing xml/html) or an xml/html string and return the formatted result for me?

Ps: want to be able to use this from my editor...

3
  • 2
    sed doesn't really have to do anything with formatting, id is a (primarily line-oriented) Stream EDitor.
    – peterph
    Oct 8, 2013 at 8:40
  • 2
    Do you mean something like "pretty printed" or indented?
    – Keith
    Oct 8, 2013 at 9:47
  • If you need this, you need to change editors. Try a 'real' one like emacs or vim.
    – terdon
    Oct 8, 2013 at 14:21

2 Answers 2

8

If its something related to pretty printing of file in xml aligned format, xmllint as suggested by @warl0ck is nice & here is what I tried & see:

$cat some.xml
<myRoot> <my-element><my-subelem myAttr="value"/></my-element></myRoot>


$ xmllint --format some.xml
<?xml version="1.0"?>
<myRoot>
  <my-element>
    <my-subelem myAttr="value"/>
  </my-element>
</myRoot>
3
  • Can it take a string as argument itself, as opposed to a file?
    – deostroll
    Oct 8, 2013 at 11:32
  • Well, I tried it by echo`ing & it worked in that case as well: xmllint --format <(echo '<myRoot> <my-element><my-subelem myAttr="value"/></my-element></myRoot>') Any specific use-case where your are seeing some failure?. Oct 8, 2013 at 11:59
  • how to utilize that for the geany editor: geany.org/manual/#sending-text-through-custom-commands
    – deostroll
    Oct 8, 2013 at 12:21
2

Try the xmllint program.

In VIM you could format the whole file in place, e.g 1,$!xmllint --format --recover -

Not the answer you're looking for? Browse other questions tagged .