need a little kick with sed, got it almost but on glitch

hi friends.

yo i have a textfile with url�s in it

sometimes middle in text, sometimes one url alone is a line

i append a string right behind the domain name

so that http://unix.com becomes http://unix.com.APPENDTHIS on all occasions.

i use this sed-line to achieve this:

sed -i "s/http:\/\/[a-zA-Z0-9\_\-\.]*/&.APPENDTHIS/g" FILE

now my problem is when the url contains a dash it messes up.

test input file:

http://alf.com/super.cgi
http://frederick.xoom.com/homepage/xy.htm
http://james_007.web1000.com/
http://unix-windows.com/bluescreen.txt
http://alf.com.APPENDTHIS/super.cgi
http://frederick.xoom.com.APPENDTHIS/homepage/xy.htm
http://james_007.web1000.com.APPENDTHIS/
http://unix.APPENDTHIS-windows.com/bluescreen.txt

the last url with the - dash in it messes up. it appends "APPENDTHIS" after the dash instead there where the domain-name ends.
what do i do wrong?
i tried to unescaped dash and double escaped also.

thanks for the needed kick.

as so soften when i request help on here,
i find the solution myself
old:

sed -i "s/http:\/\/[a-zA-Z0-9\_\-\.]*/&.APPENDTHIS/g" FILE

new, working:

sed -i "s/http:\/\/[a-zA-Z0-9\_--\.]*/&.APPENDTHIS/g" FILE

instead of escaping the dash i have to double it.

dont know why, just tested some variations and this one works.

anyone any comment why?

sed "s/http:\/\/[^\/]*/&.APPENDTHIS/g"

Should work and be cleaner...

thanks Tytalus, nice one
thats what i call a fast answer :):):):slight_smile:

this only works when the domain is trailed by a slash unix.com/ but not with unix.com

but i found a workaround now.

sed -i "s/http:\/\/[-a-zA-Z0-9\_\.]*/&APPENDTHIS/g"

this one works smooth wherever the pattern occurs, wheter a linebreak follow or binary.