Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 20 Jul 2008 13:05:49 +0530
From:      "N. Raghavendra" <raghu@mri.ernet.in>
To:        Roland Smith <rsmith@xs4all.nl>
Cc:        freebsd-questions@freebsd.org
Subject:   Re: How to divide up?
Message-ID:  <863am5atyi.fsf@riemann.mri.ernet.in>
In-Reply-To: <20080720004551.GA26045@slackbox.xs4all.nl> (Roland Smith's message of "Sun, 20 Jul 2008 02:45:51 %2B0200")
References:  <20080720002345.GA9173@thought.org> <20080720004551.GA26045@slackbox.xs4all.nl>

next in thread | previous in thread | raw e-mail | index | archive | help
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@mri.ernet.in> | http://www.retrotexts.net/
Harish-Chandra Research Institute   | http://www.mri.ernet.in/
See message headers for contact and OpenPGP information.




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?863am5atyi.fsf>