Reputation: 628
I would like to swap out every instance of "/this/name/" with "/that/name/" (within the files of a directory) - I'm just not sure how.
Is there a good way of combining the two commands below (or something equivalent) to search/regex an entire directory of files recursively?
• perl -pi -e "s/2f\x74\x68\x69\x73\x2f\x6e\x61\x6d\x65\x2f/\2f\x74\x68\x61\x74\x2f\x6e\x61\x6d\x65\x2f/g" /some/directory
• find . -name "*"
The first Perl example works fine for an individual file, just not a bunch of them. The Find example is of course just an example. I've used these two previous questions as some reference:
[Find] Unix find: multiple file types
[Perl] RegEx within perl -pi -e
Upvotes: 2
Views: 1612
Reputation: 124734
Sure, use the -exec
flag of find
find /path -type f -exec perl -pi -e "..." {} \;
I added -type f
because I think you want to execute this for files only.
Upvotes: 3