1

I need to convert my all url relative path

https://www.example.com/image/abc.gif   to  /image/abc.gif  

i tried this command but not worked for https:\\ section . How can i use https\\ in this command .

   grep -rl "http://www.example.com" /root/ | xargs sed -i 's/http://www.example.com//g'
Kernelv5
  • 1,732
  • 1
  • 10
  • 17
  • When I use `/` in my search portion for `sed`, i like to make my `/` delimiter something else for readability: `sed -i 's?some\/path\/here?new\/path\/here?g` Also, remember to escape your slashes in your search and replace strings ie. `//` becomes `\/\/`. – Coder-guy Mar 03 '15 at 18:46
  • possible duplicate of [Use slashes in sed replace](http://stackoverflow.com/questions/5864146/use-slashes-in-sed-replace) – Wintermute Mar 03 '15 at 18:48
  • Is domain always the same trough the file? eg: `www.example.com` – Jotne Mar 03 '15 at 19:00

2 Answers2

0

The following will do the job:

echo "https://www.example.com/image/abc.gif" | sed 's/https:\/\/www\.example\.com//g'

OUTPUT

/image/abc.gif
Nir Alfasi
  • 53,191
  • 11
  • 86
  • 129
0

You can use regular expressions, the -r indicates extended regexes. The ? says 0 or 1 occurrence of 's'.

echo "http://www.example.com/image/abc.gif" | sed -r 's/https?:\/\/www\.example\.com//g'
chiaboy
  • 394
  • 2
  • 6