I have some paths like this:
/www/site1.dev/public_html/test.htm /www/site2.dev/html/test.htm /www/site3.dev/public/test.htm
I’d like to pass them to a bash script and get a result back in this format:
http://site1.dev/test.htm http://site2.dev/test.htm http://site3.dev/test.htm
I’m not sure what the best way to handle the regex part of this is:
#!/bin/sh
RET='';
function trim() { echo $1; }
for ARG in "$@"
do
//do match and add existing RET value
RET= 'http://'(regular expression or find/replace here) RET
done
echo ">>$(trim $RET)<<"
Solution
My code based on Wes Hardaker’s answer
DOMAIN=`echo $ARG | sed 's#.*www/##'`
DOMAIN=`echo $DOMAIN | sed -E 's#/(public|html).*##'`
POST=`echo $ARG | sed -E 's#.*html##'`
echo 'http://'$DOMAIN$POST
The easiest way is probably to use ‘sed’. IE: