tags:

views:

24

answers:

2

Sometime we have problem with the file PATH syntax

For example

Wrong PATH as (double back slash)

     /etc//sysconfig/network

While the right syntax is

   /etc/sysconfig/network

How to fix by sed if the PATH have two double spaces (consecutive)

For example

    echo   /etc//sysconfig/network | sed …

will print

    /etc/sysconfig/network
+2  A: 

just use the shell(bash)

$ path="/etc//sysconfig/network"
$ echo ${path//\/\//\/}
/etc/sysconfig/network

otherwise, if you still prefer sed

$ echo "$path" | sed 's/\/\//\//g'
/etc/sysconfig/network
ghostdog74
what's the result of `/etc///sysconfig/network`? :) +1 for bash version
roe
if OP has that kind of data, then something is wrong during his/her string concatenation code. If such a thing should happen, then use the wildcard.
ghostdog74
Yeah, in all fairness, that wasn't in the original spec.
paxdiablo
+2  A: 

The following looks like a sine wave but it does the trick:

pax> echo /etc//sysconfig/network | sed 's/\/\/*/\//g'
/etc/sysconfig/network

It works by collapsing all occurrences of two or more / characters into a single one.

paxdiablo