Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Batch Script - Find and replace text in multiple files in a directory

I am new to writing batch scripts. I am in need of a simple batch file that searches for a text (eg., FOO) and replaces it with another text (eg., BAR) in all the text files within a folder and it's sub-folders.

I need to give this batch file to the user. So, it is not possible to ask the user to install anything else. Can someone please help me with this?

like image 863
Guhan Murugesan Avatar asked Mar 17 '23 17:03

Guhan Murugesan


1 Answers

I've used this tool extensively to accomplish similar tasks: http://fart-it.sourceforge.net/ (Despite its name, it is a very handy tool).

For example, this command performs a search of all TXT files in the "C:\Dir\To\Files" (+subfolders) replacing all occurances of FOO with BAR. The -i switch performs a case-insensitive search.

FART -i -r "C:\Dir\To\Files\*.txt" FOO BAR
like image 84
Jason Faulkner Avatar answered Mar 23 '23 01:03

Jason Faulkner