find and replace string with regexp in multiple files using ack

cyrilpetit

New Member
Credits
0
Hi everyone !
I successfully can find unquoted string in my php files, recursively, with this command line:
ack --heading --php "\[[a-zA-Z0-9_]*]"

But then, now, how to add quotes to this string ?

(FYI, My goal is to replace all constant in my php files, recursively to get rid of the Warning: Use of undefined constant.)

Any suggestions ?
 


dos2unix

Well-Known Member
Credits
1,214
I've never used ack. I've used awk. (bad humor)
Usually I use grep to search for strings.

For search and replace, I use sed.
The thing about sed is.. you need to know what you are searching for in advance.

sed -i 's/oldstring/"new string with quotes"/g' myfile.php

Just replace the old string with whatever you're searching for.
It can be an entire line of text.
Then add quotes in the "new string" section. Double quotes are easy.
single quotes need to be "escaped".
 

dos2unix

Well-Known Member
Credits
1,214
I get a find: paths must precede expression: exec when I try to run this.
 


Members online


Top