Guhan Murugesan
Guhan Murugesan

Reputation: 89

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?

Upvotes: 5

Views: 24978

Answers (2)

Jason Faulkner
Jason Faulkner

Reputation: 6558

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

Upvotes: 7

tatatat0
tatatat0

Reputation: 565

I believe your question has already been answered. At least for replacing text.

Adding more information would also be helpful in assessing your problem. Like if the text files mentioned are created by a script.

Upvotes: 0

Related Questions