将URL更改为filepath

时间:2010-12-20 04:31:58

标签: sed awk

我想基于URL路径生成文件路径。以下是URL,我想将其更改为下面给出的URL。

myurl="https://reports.company.com/users/clients/Daily/MonFile/"

/home/shantanu/company/reports.company.com/users/clients/Daily/MonFile/

前两个(/ home / shantanu /)是我的主目录。

4 个答案:

答案 0 :(得分:0)

在AWK中你可以这样做:

BEGIN {
     myurl="https://reports.company.com/users/clients/Daily/MonFile/";
     sub("https:\/\/","\/yourdir\/whatever\/",myurl);
     print myurl;
}

结果:

/yourdir/whatever/reports.company.com/users/clients/Daily/MonFile/

Running on ideone

答案 1 :(得分:0)

使用sed,

sed 's_https://_home/shantanu/company/_g'

示例:

$ myurl="https://reports.company.com/users/clients/Daily/MonFile/"
$ echo $myurl | sed 's_https://_home/shantanu/company/_g'
myurl="https://reports.company.com/users/clients/Daily/MonFile/"

答案 2 :(得分:0)

sed 's/https:\//\/home\/shantanu\/company/g'

答案 3 :(得分:0)

myurl="https://reports.company.com/users/clients/Daily/MonFile/"
echo "$myurl" | sed "s|https\?://\([^.]*\.\)\([^.]*\)\(\.*\)|$HOME/\2/\1\2\3|"