find and replace string with regexp in multiple files using ack


New Member
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 ?


Well-Known Member
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".

Members online

No members online now.