我想根據URL路徑生成文件路徑。以下是網址,我想將其更改爲下面給出的網址。將URL更改爲文件路徑
myurl="https://reports.company.com/users/clients/Daily/MonFile/"
/home/shantanu/company/reports.company.com/users/clients/Daily/MonFile/
前兩個(/ home/shantanu /)是我的主目錄。
我想根據URL路徑生成文件路徑。以下是網址,我想將其更改爲下面給出的網址。將URL更改爲文件路徑
myurl="https://reports.company.com/users/clients/Daily/MonFile/"
/home/shantanu/company/reports.company.com/users/clients/Daily/MonFile/
前兩個(/ home/shantanu /)是我的主目錄。
使用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/"
在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/
sed 's/https:\//\/home\/shantanu\/company/g'
myurl="https://reports.company.com/users/clients/Daily/MonFile/"
echo "$myurl" | sed "s|https\?://\([^.]*\.\)\([^.]*\)\(\.*\)|$HOME/\2/\1\2\3|"