On 31/05/2012 18:23, Jon Forsyth wrote:
I'm using the following line in Terminal, on OSX Lion, but I can't seem to
match parentheses '()':
perl -n -e 'print if(/\\(Submit\\)/)' visits/admin_add.ctp
I tried with one backslash in front of each '(' ')' as well to no avail.
If I remove the '\'s and '()' the match is printed like so:
<?php echo $form->end('Submit');?>
My purpose is to make sure I'm matching the correct lines including the
'()', then to alter the code to perform a search and replace on the
matches). Something like:
perl -p -i.bak -e 's/PATTERN/REPLACE/g' INPUT
Hi Jon
Backslashes within a single-quoted command-line string don't need
escaping, so a single backslash before each parenthesis is correct.
But from your output it seems you have omitted the single-quotes around
'Submit' from your pattern, and that is why it isn't matching.
With a conflict of single quotes and backslashes it is probably better
if you write a short program than try to get it working on the command
line, but
perl -n -e 'print if(/\(\'Submit\'\)/)' visits/admin_add.ctp
or
perl -n -e "print if(/\\('Submit'\\)/)" visits/admin_add.ctp
are the correct forms for use on the command-line.
HTH,
Rob
--
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/