I am trying to come up with a script to format forwards for apache, what I need to do is take a url, strip off the domain and then attach a "/" to the end of the line IF there is not one there already, now the script I have come up with is this:
#!/bin/bash
sed 's/http:\/\/www.mydomain.co.uk//g' address > address1
sed -e 's/$/\//' address1 > address2
now this script will take off the "http://www.mydomain.co.uk" at the begining and add a "/" at the end, but some of the url's I have already have the "/" there. how can I get sed to only add the "/" if its not already there?
Match a character other than a slash at the end of the line and replace with the match (&
) plus a slash:
sed 's![^/]$!&/!'
To make things a little easier, I changed the delimiter from /
to !
, so that the slashes in the find/replace parts don't need to be escaped.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With