I have a text:
abc abc ABC ABC AB_C
I want to combine words with capital letters and dashes (this is not necessary).
My decision:
[A-Z]+(_{0,1}[A-Z]+)+
And it works on regexpal.com , but it does not work with sed. What am I doing wrong?
sed
sed 's/\([A-Z]+(_{0,1}[A-Z]+)+\)/\1/g'
This regular expression is not supported in traditional sed. You can use grep -oP(with PCRE flag)
grep -oP
s='abc abc Abc ABC AB_C' grep -oP '([A-Z]+(_?[A-Z]+)+)' <<< "$s" ABC AB_C
seduses BRE by default . this means that you need to avoid characters with special meaning, for example + ( .... "attach" them special significance.
+ ( ...
gnu sed, -r, sed ERE.
-r
ERE
, .
:
sed :
$ echo 'abc abc Abc ABC AB_C' | sed "s/\s/\n/g" | sed '/[a-z]/d' ABC AB_C
grep using and not pcre:
$ echo 'abc abc Abc ABC AB_C' | sed "s/\s/\n/g" | grep "^[A-Z][A-Z_]*$" ABC AB_C