开发者

sed + fix PATH syntax with sed

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


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜