I am writing a batch file script using Windows command-line environment and want to change each occurrence of some text in a file (ex. "FOO") with another (ex. "BAR"). What is the simplest way to do that? Any built in functions?
31 Answers
I have faced this problem several times while coding under Visual C++. If you have it, you can use Visual studio Find and Replace Utility. It allows you to select a folder and replace the contents of any file in that folder with any other text you want.
Under Visual Studio: Edit -> Find and Replace In the opened dialog, select your folder and fill in "Find What" and "Replace With" boxes. Hope this will be helpful.
3 Comments
Aibrean
Nadjib, your answer doesn't help the user because your assuming they are using software of which they make no mention. Please suggest an option that doesn't require software.
Paul
@Aibrean the answer is no use, but not for that reason, it's the entry point that is wrong.
Jason
This response does not deserve the downvotes. In a Windows environment, there aren't a lot of good options to solve the OP's problem. I happen to code in VS and found this to be an excellent answer, and saved me a ton of time hunting for another solution. Replaced 20k+ occurrences in over 2k files across 3 directories in less than a min.