I'm not sure why you would need perl
in this case, and I'm not sure who Hazel is and why she would run your shell script, but since you've flagged your question shell
and are obviously using bash
, I'll provide a shell-only answer. Note that this will work in other shells too, not just bash.
#!/bin/bash
find /Users/admin/Downloads/ -type f -name "*.txt" \
-exec sed -i '' -e 's/OldText/NewText/g' {} \;
Note that this find
command is split into two lines for easier readability. It uses sed
instead of perl
because sed
is smaller and likely faster, and is considered a standard shell tool whereas perl
may not be found on all systems.
Note also that the exact syntax of the sed
options I've used may depend on the implementation of sed that is on your system.
The find
command works like this:
find [path ...] [command ...]
You can man find
to see the details, but the command I've provided here does the following.
- Starts in
/Users/admin/Downloads/
-type f
- Looks for things that are files (as opposed to directories or symlinks)
-name "*.txt"
- AND looks for things that match this filespec
-exec ...
- AND executes the following shell command, replacing {}
with the filename that's been found.