I am using this command to search and replace a string with another in the command prompt:
perl -pi -i.bak -e "s/Mohan/Sitaram/g" ab.txt
This replaces Mohan
with Sitaram
in the file ab.txt
in the current directory.
However I want to replace all occurrences of Mohan
with Sitaram
in all .txt
files in all the sub-directories (recursively). Using *.txt
instead of ab.txt
doesn’t work. Regular expressions work otherwise as I have downloaded the regex packages for Windows. It doesn’t work only for this command saying
E:\>perl -pi -e "s/Sitaram/Mohan/g" *.txt
Can't open *.txt: Invalid argument.
Is there any way to fix this? A different command perhaps?
find . -name "*.txt" | xargs perl -p -i -e "s/Sitaram/Mohan/g"
find
is used to search all *.txt files recursively.
xargs
is used to build and execute command lines from standard input.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With