Mailinglist Archive: opensuse (818 mails)

< Previous Next >
Re: [opensuse] Java script assistance (slightly OT)

On Mon, 19 Sep 2011, Per Jessen wrote:
sed -e 's/{/\n{/g' -e s'/}/}\n/g' -e s'/;/;\n/g' <filename

(still not sure if you need to escape the curly brackets).

You don't, as sed uses basic regular expressions (see 'man 7 regex'),
so you need to escape {} to get "special" behaviour (if any).

And you don't need to use -e for each expression, just use:

sed -e 's/{/\n{/g; s/}/}\n/g; s/;/;\n/g' <filename

or more readble:

sed -e 's/{/\n{/g;
s/;/;\n/g' <filename

Albeit, there are some rare cases where you do need to use '-e'
multiple times, IIRC when one expression has to work on the result(!)
of a previous expression, but apparently GNU sed 4.2.1 has got that

Oh, and JFTR: not every sed handles '\n'! E.g. GNU sed up until a few
years ago (at least a 10yr old one didn't). In those cases, you have
to embed the (masked by backslash) linebreaks literally:

sed -e 's/{/\
/g' <filename

BTW: I prefer the linebreak after the '{' of a block, i.e.:

sed -e 's/{/{\n/g; s/}/}\n/g; s/;/;\n/g'


Unsubscribing from a mailing list you subscribed to is a basic IQ
test for Internet users.
-- Author unknown, seen on the PCR-1000 list
To unsubscribe, e-mail: opensuse+unsubscribe@xxxxxxxxxxxx
For additional commands, e-mail: opensuse+help@xxxxxxxxxxxx

< Previous Next >
Follow Ups