Is there a way to use regexes in sed without having to put backslash everywhere?
To use regex syntax in sed, you have to put in \
before (
, {
, etc. to use them as special characters. For example:
~ > echo 123 | sed 's/[开发者_如何学JAVA0-9]{2}/x/'
123
vs.
~ > echo 123 | sed 's/[0-9]\{2\}/x/'
x3
This is the reverse of what I'm used to. Is there any way to make characters have special meanings by default?
Try:
echo 123 | sed -r 's/[0-9]{2}/x/'
If your sed
doesn't have -r
:
echo 123 | perl -pe 's/[0-9]{2}/x/'
精彩评论