我无法让 sed 识别其模式字符串中的连字符和下划线。
有谁知道为什么
[a-z|A-Z|0-9|\-|_]
在下面的例子中像
[a-z|A-Z|0-9|_]
?
$ cat /tmp/sed_undescore_hypen
lkjdaslf lkjlsadjfl dfpasdiuy service-type = service-1; jaldkfjlasdjflk address = address1; kldjfladsf
lkjdaslf lkjlsadjfl dfasdf service-type = service_1; jaldkfjlasdjflk address = address1; kldjfladsf
$ sed 's/.*\(service-type = [a-z|A-Z|0-9|\-|_]*\);.*\(address = .*\);.*/\1 \2/g' /tmp/sed_undescore_hypen
lkjdaslf lkjlsadjfl dfpasdiuy service-type = service-1; jaldkfjlasdjflk address = address1; kldjfladsf
service-type = service_1 address = address1
$ sed 's/.*\(service-type = [a-z|A-Z|0-9|\-]*\);.*\(address = .*\);.*/\1 \2/g' /tmp/sed_undescore_hypen
service-type = service-1 address = address1
lkjdaslf lkjlsadjfl dfasdf service-type = service_1; jaldkfjlasdjflk address = address1; kldjfladsf
$ sed 's/.*\(service-type = [a-z|A-Z|0-9|_]*\);.*\(address = .*\);.*/\1 \2/g' /tmp/sed_undescore_hypen
lkjdaslf lkjlsadjfl dfpasdiuy service-type = service-1; jaldkfjlasdjflk address = address1; kldjfladsf
service-type = service_1 address = address1