Reputation: 253
I have a bunch of XML-files that all start with the XML-declaration
<?xml version="1.0" encoding="UTF-8"?>
After the final ">" it just goes on directly with the start of the following tag - like this: <?xml version="1.0" encoding="UTF-8"?><tag>
I would like to split it there to make a new line followed by another new line. Like this:
<?xml version="1.0" encoding="UTF-8"?>
New line
New line
<tag>
How could this be done?
Many thanks in advance:-)
/Paul
Upvotes: 0
Views: 904
Reputation: 10039
based on your definition (start with) and content
sed '1 {
/<[?]xml/ {
s/<tag>//
a \
new line 1 (whatever also just a \n like "new line 2") \
\
<tag>
}
}' YourFile
\
char) with a bit of security (take only 1st line and starting with ?xml
)-i
for inline modification on GNU sedUpvotes: 0
Reputation: 5298
With sed
:
AMD$ sed 's/<?xml version="1.0" encoding="UTF-8"?>/&\n\n\n/' File
<?xml version="1.0" encoding="UTF-8"?>
<tag>
Just replace the pattern <?xml version="1.0" encoding="UTF-8"?>
with the same pattern followed by 3
newlines (this will create 2
newlines before <tag>
.
Use sed -i.bak 's/<?xml version="1.0" encoding="UTF-8"?>/&\n\n\n/' File
for inplace substitution.
Upvotes: 2