[英]Search and Replace SED Linux
我需要轉換所有網址的相對路徑
https://www.example.com/image/abc.gif to /image/abc.gif
我嘗試了此命令,但不適用於https:\\\\
section。 我如何在此命令中使用https\\\\
。
grep -rl "http://www.example.com" /root/ | xargs sed -i 's/http://www.example.com//g'
以下將完成工作:
echo "https://www.example.com/image/abc.gif" | sed 's/https:\/\/www\.example\.com//g'
OUTPUT
/image/abc.gif
您可以使用正則表達式,-r表示擴展的正則表達式。 ? 說0或1出現的“ s”。
echo "http://www.example.com/image/abc.gif" | sed -r 's/https?:\/\/www\.example\.com//g'
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.