I find all needed files with grep: grep --include=\*.{php,ini,conf,sh} -ril -P "'([\d\w\-\_\.]+)(@domain.com)'" '/var/www_data/somepath/'
Now I assume it's either use of sed or perl to for replacement process, alas I can't figure out how to use above regexp in either of them.
I saw this way and this way but as I said, I couldn't get it work with my pattern (and by that I mean that I get > in the next line after executing command. I assume it's problem with regexp shown above when used with sed or perl), so any advice on that matter would be nice.
Also, I don't know if it's possible (it's not really important) but I'd like to print some string for each file in with replacement occurred, for example File fixed: /path/to/file/
(file names taken from grep list maybe?)
Best Answer
Typically, when you get a
>
in the next line after hitting, it means that one of your quotes isn't closed yet. I couldn't find that mistake in your regex. But you do not need to surround the path/var/www_data/somepath/
with single quotes. I assume there are no unusual characters insomepath
?Anyways, I tested your regex with sed.
\d\w
look likevim
syntax for me, that's why I translated it to ascii (which always works). Also, inside of[]
you do not need to escape.
:Indeed you can use
sed
orperl
for your task. You don't necessarily needgrep
to generate a file list, unless you have GB of data. Then presorting could result in a speed benefit.To test your regex, you could do the following:
When you're satisfied with the result, just add the
-ibak
(--in-place=bak
) argument and run it on all filesThe original files are being put into
<orignalname.php>.bak
.To answer your last question. For this job,
grep
is the tool you want, you could run it on the.bak
files generated by sed above:or, simply: