Mailinglist Archive: opensuse (2488 mails)

< Previous Next >
Re: [opensuse] Bash script help needed
  • From: Randall R Schulz <rschulz@xxxxxxxxx>
  • Date: Mon, 5 Feb 2007 13:09:37 -0800
  • Message-id: <200702051309.37783.rschulz@xxxxxxxxx>
On Monday 05 February 2007 12:46, Jan Karjalainen wrote:
> To continue on the same subject, how do I remove extra spaces from
> the list?
>
> 111.222.111.222 - 222.111.222.111,on
>
> should be
>
>
> 111.222.111.222-222.111.222.111,on
>
> Note that there should be no spaces around the "-" sign.

sed -e 's/ *- */-/'


If multiple occurrences of spurious spaces surrounding hyphens may occur
on a single line, use the 'g' modifier:

sed -e 's/ *- */-/g'


If you want all spaces everywhere expunged, do this:

sed -r -e 's/ +//g'


It's good to be aware the Gnu sed can do so-called extended regular
expressions matching if the "-r" option is included, as I did in the
last example above. Naturally, this must be used with care, since many
aspects of the RE syntax changes under the extended form.

The same effect can be achieved in this case without extended REs like
this:

sed -r -e 's/ *//g'

NOTE: In this example there are _two_ spaces before the asterisk.


You can combine multiple expressions in a single invocation by simply
giving multiple pairs of "-e" and editing expressions. They'll be
interpreted in order, in case one expression's applicability depends on
the application of another.


> /J


Randall Schulz
--
To unsubscribe, e-mail: opensuse+unsubscribe@xxxxxxxxxxxx
For additional commands, e-mail: opensuse+help@xxxxxxxxxxxx

< Previous Next >