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.
精彩评论