replacing text but starting on a new line

Microsoft Windows xp professional w/sp2
July 30, 2010 at 07:21:14
Specs: Windows XP
I'm trying to replace text in a text file using the following batch file but would like the new text to start on a new line. I can't figure out how to accomplish this.

@echo off > newfile.txt
setLocal EnableDelayedExpansion

if exist newfile.txt del newfile.txt
set /p new= What is the new data?
set /p old= What data is to be replaced?


for /f "tokens=* delims= " %%a in (myfile.txt) do (
set str=%%a
set str=!str:%old%=%new%!
echo !str! >> newfile.txt
)
del myfile.txt
rename newfile.txt myfile.txt


See More: replacing text but starting on a new line

Report •

#1
July 30, 2010 at 13:01:13
Right now if text file has

test this replcement old and the rest of the data will follow.

run batch and replace old with new I get.

test this replcement new and the rest of the data will follow.

I want following:

test this replcement
new and the rest of the data will follow.


Report •
Related Solutions


Ask Question