Replace text in file

July 11, 2009 at 09:41:31
Specs: Windows Vista, 4/g
I would like to write a text file with about 10 lines, each one with this format:

<div name = "content" 1/NAMEcr.jpg</div>

but replace NAME with a different text string for each line. I would like to be able to pass the strings as parameters to the batch file e.g. file.bat string1 string2 string3... etc.

Thanks!
Tom


See More: Replace text in file

Report •


#1
July 11, 2009 at 13:18:14
Here the script you wish. Replace file_IN and file_OUT values with your file names and run.

:: EDFILE.BAT Usage: edfile Par1 Par2 ... ParN
@echo off & setlocal EnableDelayedExpansion

set file_IN=myfile.txt
set File_OUT=output.txt

type nul > %file_OUT%
set tail=%*
for /F "delims=" %%i in ('type %file_IN%') do (
  set line=%%i
  for /F "tokens=1*" %%j in ('echo.!tail!') do (
    set line=!line:/NAME=/%%j!
    set tail=%%k
  )
  echo.!line!>> %file_OUT%
)
:: End_Of_Batch


Report •

#2
July 11, 2009 at 15:04:58
Sorry, the output file comes out like this:
!line!
!line!
!line!
!line!
!line!
!line!
!line!
!line!
!line!
!line!


Report •

Related Solutions


Ask Question