mercredi 28 janvier 2015

Why does regex with \{ work with egrep, but not with sed?


Given a text like this



./RFF_09 -f${FILE} -c${COND}


inside a file, this egrep command will correctly match:



egrep './RFF(.*) (.*)-c\\$\{COND\}' file


but this sed command will not



sed -n "s:'./RFF(.*) (.*)-c\\$\{COND\}':./RFF$1 $2-cRFF$1:gp"


It will fail with sed: -e expression #1, char 38: invalid content of \{\}. I've also tried with



sed -n "s:'./RFF(.*) (.*)-c\\$\{COND\}':DUMMY:gp" file
sed -n s:'./RFF(.*) (.*)-c\\$\{COND\}':DUMMY:gp file


with the same result.



sed -n "s:'./RFF(.*) (.*)-c\\$\\{COND\\}':DUMMY:gp" file


Will not give me an error message, but will not match.


What am I doing wrong? Or better: How can I replace the text as suggested by the original command? I'm using rather old versions of sed (4.1.2) and egrep (2.5.1), so a workaround is appreciated even if you can't reproduce the error with newer versions.



Aucun commentaire:

Enregistrer un commentaire