replace in-place using perl changed soft link/symlink to static file

  • A+

Given the following command:

git ls-files | xargs perl -i -pe 's/SEARCHTERM/REPLACETERM/g' 

All outputs to perl (from git ls-files) that were symbolic links are now copies of the target files.

I have two questions:

1) I think I vaguely understand why this happened, but only vaguely. Can someone explain in detail? And suggest the best mechanism for avoiding this? Expected behavior would be that the symbolic link targets would be the target of the read AND the write--not just the read.

2) Is there a better general approach for doing a search and replace on a local git branch?

Might be worth noting that my bash is pretty rudimentary and xargs is just my default goto when I want to ensure the contents of files are processed rather than a list of files. Not used for any reason other than that.


If you're not opposed to using sed, give this a whirl:

git ls-files | xargs -I{} -P4 sed --follow-symlinks -i'' 's/SEARCHTERM/REPLACETERM/g' {}  


:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: