I am using Perl to search and replace multiple regular expressions:
When I execute the following command, I get an error:
prompt> find "*.cpp" | xargs perl -i -pe 's/##(\W)/\1/g' -pe 's/(\W)##/\1/g'
syntax error at -e line 2, near "s/(\W)##/\1/g"
Execution of -e aborted due to compilation errors.
xargs: perl: exited with status 255; aborting
Having multiple -e is valid in Perl, then why is this not working? Is there a solution to this?
Several
-e‘s are allowed.You are missing the
';'Perl statements has to end with
;.Final statement in a block doesn’t need a terminating semicolon.
So a single
-ewithout;will work, but you will have to add;when you have multiple-estatements.