5

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?

Guhan Murugesan
  • 89
  • 1
  • 1
  • 8

2 Answers2

7

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
Jason Faulkner
  • 6,378
  • 2
  • 28
  • 33
  • Thanks for your response. As I had mentioned in my post, I have to send this batch file to the user and most probably the user will not accept to do any installations, including FART. Is there any way this can be accomplished without any additional installations? – Guhan Murugesan Dec 05 '14 at 03:10
  • 1
    @GuhanMurugesan - It doesn't require installation. Just copy the fart.exe over with your BAT file in the same directory. – Jason Faulkner Dec 05 '14 at 03:18
0

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.

Community
  • 1
  • 1
tatatat0
  • 437
  • 1
  • 5
  • 11
  • Thanks for your response. I have a large number of text files in a folder, which also has a few sub folders each of which has some text files. The text files were not created by any scripts. Most of these text files contain the name of a person which needs to be replaced by a different name. – Guhan Murugesan Dec 05 '14 at 01:52