The very first -i after opening the file is unlink , so you cannot use -i for files that you do not want to modify.
find src -type f -exec grep -Pl 'pattern' {} + | xargs perl -i -pe's/pattern/replacement/g'
Of course, grep can already do recursive searches, so if you donβt need to use find to filter the results you specify later, you can use
grep -Plr 'pattern' src | xargs perl -i -pe's/pattern/replacement/g'
Note: cmd | xargs perl ... cmd | xargs perl ... can handle more files than perl ... $( cmd ) .
ikegami
source share