我想基于URL路径生成文件路径。以下是URL,我想将其更改为下面给出的URL。
myurl="https://reports.company.com/users/clients/Daily/MonFile/"
/home/shantanu/company/reports.company.com/users/clients/Daily/MonFile/
前两个(/ home / shantanu /)是我的主目录。
答案 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/
答案 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|"