Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

My xml file looks like this:

<price = "2.22"><instock = "1">

I need to have it like that:

<price = "2.22">
<instock = "1">

After each ">" character I need to put a newline character with awk or sed. How can i accomplish that? thank you

share|improve this question
    
I'm not sure <price = "2.22"> is valid XML. –  grawity Sep 20 '10 at 17:19
add comment

2 Answers

As KeithB said, there are potential problems that can arise from using a crude approach. However, this crude approach is a tiny bit more selective so that chances it will fail are reduced by about 0.00001% which may be enough.

sed 's|><|>\n<|g' inputfile

If there may be whitespace between the angle brackets, then this may be better:

sed 's|>[[:space:]]*<|>\n<|g' inputfile

which will eliminate that whitespace.

share|improve this answer
add comment

If you want to do this right, you need something more powerful than awk. One of the problems is awk won't handle > inside strings or comments. You might be better off with perl or python. If this is just to make a file easier to look at visually, it might be fine.

A quick and dirty awk script is

 awk '{for(i=1; i<= NF-1; i++) printf "%s>\n",$i}' FS='>'

This treats > as the separator between fields, and prints out each on its own line. Its pretty crude, but might be a starting place.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.