Need batch script to find/replace values in all files/folder

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
chanchal21pes
Posts: 3
Joined: 21 Jan 2014 21:33

Need batch script to find/replace values in all files/folder

#1 Post by chanchal21pes » 21 Jan 2014 21:38

Hello,
I am new to batch scripting. I need a complete batch script to find (set of given values) and replace them with new values in all the files in the folder and sub folder. Please help :oops:

The files might not be .txt always.

Sample file content:

./adt_btth/cfg/wf_btth.cfg:$BadFile_1=/atadata/ipm/adt_btth/badfiles/VSYM_PROD.bad
./adt_btth/cfg/wf_btth.cfg:$PMSessionLogFile=/export/home/ipm/adt_btth/logs/sessions/s_concate_usoc.log

(string in bold above needs to be replaced with new path.

New Value will look like:

./adt_btth/cfg/wf_btth.cfg:$BadFile_1=/Info_new/Info/NDW/badfiles/VSYM_PROD.bad
./adt_btth/cfg/wf_btth.cfg:$PMSessionLogFile=/home/logs/info/NDW/logs/sessions/s_concate_usoc.log

There will be many such lines in one file and then many files in a folder and subfolders.

Please help. Please let me know if i should give more information here.

Squashman
Expert
Posts: 4488
Joined: 23 Dec 2011 13:59

Re: Need batch script to find/replace values in all files/fo

#2 Post by Squashman » 21 Jan 2014 22:37

Just in case some one else might have answered the question on the other forums this question has been posted on, here it is on another site.

http://www.computerhope.com/forum/index ... 391.0.html

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Need batch script to find/replace values in all files/fo

#3 Post by foxidrive » 21 Jan 2014 22:44

Thanks squashman.

Posting a question on multiple sites seems to happen a lot - and the poster will probably get a solution and then disappear without informing every site.

chanchal21pes
Posts: 3
Joined: 21 Jan 2014 21:33

Re: Need batch script to find/replace values in all files/fo

#4 Post by chanchal21pes » 22 Jan 2014 03:44

Thanks for your reply but i am supposed to be using a batch script(.bat) and not any tool.

chanchal21pes
Posts: 3
Joined: 21 Jan 2014 21:33

Re: Need batch script to find/replace values in all files/fo

#5 Post by chanchal21pes » 22 Jan 2014 03:51

Thanks alot for your reply but my requirement is to create a batch file (.bat) and not to use any tool.

Squashman
Expert
Posts: 4488
Joined: 23 Dec 2011 13:59

Re: Need batch script to find/replace values in all files/fo

#6 Post by Squashman » 22 Jan 2014 07:19

chanchal21pes wrote:Thanks for your reply but i am supposed to be using a batch script(.bat) and not any tool.

Nobody suggested you use another tool.

ShadowThief
Expert
Posts: 1167
Joined: 06 Sep 2013 21:28
Location: Virginia, United States

Re: Need batch script to find/replace values in all files/fo

#7 Post by ShadowThief » 22 Jan 2014 20:33

Squashman wrote:
chanchal21pes wrote:Thanks for your reply but i am supposed to be using a batch script(.bat) and not any tool.

Nobody suggested you use another tool.

http://www.computerhope.com/forum/index ... #msg900207 mentioned "a tool that does well with string manipulation." TC apparently stopped reading after that sentence, or they would have seen the pseudocode in the next paragraph.

ShadowThief
Expert
Posts: 1167
Joined: 06 Sep 2013 21:28
Location: Virginia, United States

Re: Need batch script to find/replace values in all files/fo

#8 Post by ShadowThief » 22 Jan 2014 20:39

Also, somebody is going to suggest that you use repl.bat (http://www.dostips.com/forum/viewtopic.php?f=3&t=3855).

Post Reply