Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Regex 如何在赛前和赛后对图案进行sed_Regex_Bash_Sed - Fatal编程技术网

Regex 如何在赛前和赛后对图案进行sed

Regex 如何在赛前和赛后对图案进行sed,regex,bash,sed,Regex,Bash,Sed,我目前正在尝试从url获取特定参数 我的url看起来像:https://private.io/report-artifact/dsop-pipeline-artifacts/container-scan-reports/redhat/ubi/ubi7/7.8/2020-02-14T222203.548_2868/ubi7-7.8.tar 我只想要redhat/ubi/ubi7/7.8 我可以通过以下操作获得redhat/ubi/ubi7/7.8/2020-02-14T222203.548_286

我目前正在尝试从url获取特定参数

我的url看起来像:
https://private.io/report-artifact/dsop-pipeline-artifacts/container-scan-reports/redhat/ubi/ubi7/7.8/2020-02-14T222203.548_2868/ubi7-7.8.tar

我只想要
redhat/ubi/ubi7/7.8

我可以通过以下操作获得
redhat/ubi/ubi7/7.8/2020-02-14T222203.548_2868/ubi7-7.8.tar

echohttps://private.io/report-artifact/dsop-pipeline-artifacts/container-scan-reports/redhat/ubi/ubi7/7.8/2020-02-14T222203.548_2868/ubi7-7.8.tar |sed的|.*/container scan reports/| |'

因此,我想删除
/2020-02-14T222203.548_2868/ubi7-7.8.tar


我还想将
/
更改为
-
,这样我就有了带有GNU
sed的
redhat-ubi-ubi7-7.8

*/container scan reports/
之后获取以下4个路径元素,并将所有
/
替换为
-

url='https://private.io/report-artifact/dsop-pipeline-artifacts/container-scan-reports/redhat/ubi/ubi7/7.8/2020-02-14T222203.548_2868/ubi7-7.8.tar'
echo "$url" | sed -E 's|.*/container-scan-reports/(([^/]*/){3}[^/]*).*|\1|;s|/|-|g'
或者您可以在
*/container scan reports/
之后获取所有内容,但不能获取最后两个路径元素:

echo "$url" | sed -E 's|.*/container-scan-reports/(.*)/[^/]*/[^/]*|\1|;s|/|-|g'

使用GNU
sed

*/container scan reports/
之后获取以下4个路径元素,并将所有
/
替换为
-

url='https://private.io/report-artifact/dsop-pipeline-artifacts/container-scan-reports/redhat/ubi/ubi7/7.8/2020-02-14T222203.548_2868/ubi7-7.8.tar'
echo "$url" | sed -E 's|.*/container-scan-reports/(([^/]*/){3}[^/]*).*|\1|;s|/|-|g'
或者您可以在
*/container scan reports/
之后获取所有内容,但不能获取最后两个路径元素:

echo "$url" | sed -E 's|.*/container-scan-reports/(.*)/[^/]*/[^/]*|\1|;s|/|-|g'

知道字符串中的位置后,可以使用
cut

echo "${string}" | cut -d/ -f 7-10 | tr '/' '-'
sed的另一种方法是

echo "${string}" | sed -E 's#([^/]*/){6}([^/]*)/([^/]*)/([^/]*)/([^/]*).*#\2-\3-\4-\5#'

知道字符串中的位置后,可以使用
cut

echo "${string}" | cut -d/ -f 7-10 | tr '/' '-'
sed的另一种方法是

echo "${string}" | sed -E 's#([^/]*/){6}([^/]*)/([^/]*)/([^/]*)/([^/]*).*#\2-\3-\4-\5#'
sed-E的| ^([^/]*/){6}| |;s |(/[^/]*){2}$| |;s |/|-| g'
sed-E的| ^([^/]*/){6}| |;s |(/[^/]*){2}$| |;s |/|-| g'