# stripping http and https from a url using sed

**URL:** <https://community.unix.com/t/stripping-http-and-https-from-a-url-using-sed/246130>\
**Category:** Shell Programming and Scripting\
**Created:** [August 3, 2009, 8:39am UTC](https://community.unix.com/t/stripping-http-and-https-from-a-url-using-sed/246130 "2009-08-03T08:39:12Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![vickylife](https://community.unix.com/letter_avatar/vickylife/32/6_449c533f586939b6e5f246632a46421f.png) [@vickylife](https://community.unix.com/u/vickylife)\
**Post date:** [August 3, 2009, 8:39am UTC](https://community.unix.com/t/stripping-http-and-https-from-a-url-using-sed/246130/1 "2009-08-03T08:39:12Z")

</div>

I have to write a sed script which removes http and https from a URL. So if  
a URL is [https://www.example.com](https://www.example.com) or [Example Web Page](http://www.example.com), script should return me [Example Web Page](http://www.example.com)

i tried echo $url | sed 's|^http[s]://||g'. It doesn't work. Please help

---

<div class="post-metadata">

**Author:** ![johnbach](https://community.unix.com/letter_avatar/johnbach/32/6_449c533f586939b6e5f246632a46421f.png) [@johnbach](https://community.unix.com/u/johnbach)\
**Post date:** [August 3, 2009, 8:54am UTC](https://community.unix.com/t/stripping-http-and-https-from-a-url-using-sed/246130/2 "2009-08-03T08:54:19Z")

</div>

```nohighlight
echo 'https://www.example.com' |sed 's/https\?:\/\///'

```

---

<div class="post-metadata">

**Author:** ![clx](https://community.unix.com/letter_avatar/clx/32/6_449c533f586939b6e5f246632a46421f.png) [@clx](https://community.unix.com/u/clx)\
**Post date:** [August 3, 2009, 8:57am UTC](https://community.unix.com/t/stripping-http-and-https-from-a-url-using-sed/246130/3 "2009-08-03T08:57:34Z")

</div>

```nohighlight
echo "https://www.example.com" | sed 's~http*://~~g'

```

---

<div class="post-metadata">

**Author:** ![dr.house](https://community.unix.com/letter_avatar/dr.house/32/6_449c533f586939b6e5f246632a46421f.png) [@dr.house](https://community.unix.com/u/dr.house)\
**Post date:** [August 3, 2009, 11:06am UTC](https://community.unix.com/t/stripping-http-and-https-from-a-url-using-sed/246130/4 "2009-08-03T11:06:47Z")

</div>

> [@vickylife](#):
>
> sed 's|^http[s]://||g'

Based on your own approach:

```plaintext
sed 's/^http\(\|s\):\/\///g'

```

Or, less geeky, less cryptic: 😉

```plaintext
sed -e 's/^http:\/\///g' -e 's/^https:\/\///g'

```

---

<div class="post-metadata">

**Author:** ![ryandegreat25](https://community.unix.com/letter_avatar/ryandegreat25/32/6_449c533f586939b6e5f246632a46421f.png) [@ryandegreat25](https://community.unix.com/u/ryandegreat25)\
**Post date:** [August 3, 2009, 11:25am UTC](https://community.unix.com/t/stripping-http-and-https-from-a-url-using-sed/246130/5 "2009-08-03T11:25:09Z")

</div>

try

```nohighlight
-bash-3.00$ echo $site
https://www.example.com
-bash-3.00$ echo ${site#*//}
www.example.com
-bash-3.00$

```
