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...

closed as unclear what you're asking by Gilles, slm, jasonwryan, rahmu, Anthon Oct 9 '13 at 4:01

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

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

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"?>
    <my-subelem myAttr="value"/>
  • Can it take a string as argument itself, as opposed to a file? – deostroll Oct 8 '13 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?. – user1587504 Oct 8 '13 at 11:59
  • how to utilize that for the geany editor: geany.org/manual/#sending-text-through-custom-commands – deostroll Oct 8 '13 at 12:21

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 or ask your own question.