I\'m having trouble getting sed to recognize both hyphen and underscore in its pattern string.
Does anyone know why
[a-z|A-Z|0-9|\\-|_]
$ sed 's/.*\(service-type = [a-z|A-Z|0-9|_-]*\);.*\(address = .*\);.*/\1 \2/g' sed_underscore_hypen.txt
service-type = service-1 address = address1
service-type = service_1 address = address1
pknga_000@miro MINGW64 ~/Documents
$ sed 's/.*\(service-type = [-a-z|A-Z|0-9|_]*\);.*\(address = .*\);.*/\1 \2/g' sed_underscore_hypen.txt
service-type = service-1 address = address1
service-type = service_1 address = address1
To match a hyphen in a character class, it must not be placed between two characters, otherwise it will be interpreted as a range operator. So to match a hyphen, place it at the beginning or end of the character class: and no escaping is necessary. See this answer for explanation: https://stackoverflow.com/a/4068725