How to divide up?
N. Raghavendra
raghu at mri.ernet.in
Sun Jul 20 07:42:12 UTC 2008
At 2008-07-20T02:45:51+02:00, Roland Smith wrote:
> Insert a newline in front of every < :
>
> gsed -e "s/</\n</g" <infile >outfile
>
> Note that this requires GNU sed. It won't work with BSD sed.
It is possible with native `sed' if the newline character in the
replacement string is properly escaped: two backslashes, followed by
Ctrl-V, and then the newline.
[/home/raghu]% which sed
/usr/bin/sed
[/home/raghu]% echo '<hello>world</hello><hello>next world</hello>' | sed 's/</\\
</g'
<hello>world
</hello>
<hello>next world
</hello>
However, this doesn't do what the OP wanted: "world", etc., must
appear on separate lines. Here is a second approximation:
[/home/raghu]% cat foo.sed
s/</\
</g
s/>/>\
/g
[/home/raghu]% cat foo.html
<hi><hello>world</hello>between hells...<hello>next world</hello></hi>
[/home/raghu]% sed -f foo.sed foo.html | sed '/^$/d'
<hi>
<hello>
world
</hello>
between hells...
<hello>
next world
</hello>
</hi>
Perhaps the pipe to remove blank lines can be incorporated into
`foo.sed', but I don't know how.
Raghavendra.
--
N. Raghavendra <raghu at mri.ernet.in> | http://www.retrotexts.net/
Harish-Chandra Research Institute | http://www.mri.ernet.in/
See message headers for contact and OpenPGP information.
More information about the freebsd-questions
mailing list