开发者

sed + fix PATH syntax with sed

开发者 https://www.devze.com 2023-01-09 09:34 出处:网络
Sometime we have problem with the file PATH syntax开发者_如何学编程 For example Wrong PATH as (double back slash)

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

精彩评论

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