I am looking for a batch script that can find and replace a string in a text file and send it to another file . Its just like the find and replace function in text or excel
The order should remain the same. Does anyone has a batch script built for this?
Here is the sample file
I have these random words and the string "water" should be replaced with "air"
Input file
========
water blubber water cloud moon water water school network hammer walking violently mediocre literature
water two window cords water zebra internet water
xylophone water home dog water ink water fun water banana uncle water mega water awesome attach water
Output file:
==========
air blubber air cloud moon air air school network hammer walking violently mediocre literature
air two window cords air zebra internet air
xylophone air home dog air ink air fun air banana uncle air mega air awesome attach air
Script to find and replace a string in a text file
Moderator: DosItHelp
Re: Script to find and replace a string in a text file
For a robust solution there is findrepl and jrepl.
The lower code changes your original file with the altered text.
findrepl
viewtopic.php?f=3&t=4697
jrepl
viewtopic.php?f=3&t=6044
Code: Select all
call findrepl "water" "air" <"yourfile.txt" >"your new file.txt"
Code: Select all
call jrepl "water" "air" /L /f "yourfile.txt" /o -
The lower code changes your original file with the altered text.
findrepl
viewtopic.php?f=3&t=4697
jrepl
viewtopic.php?f=3&t=6044