Pages

Showing posts with label batch script edit in file. Show all posts
Showing posts with label batch script edit in file. Show all posts

Tuesday, December 11, 2012

Batch Script for editing something in a file in DOS

The below Batch script will find something inside a file and replace it with something of your wish 

@echo off
setlocal enabledelayedexpansion

if not exist "%1" (echo this file does not exist...)&goto :eof

set  /p findthis=Enter here what you want to find:
set  /p replacewith=Enter here what you want to replace:
for /f "delims= tokens=* eol=^ " %%a in (%1) do (
   set write=%%a
   if %%a==!findthis! set write=!replacewith!
   echo !write!

   echo !write!>>%~n1.replaced%~x1
)


donot add a space after the varialbe in the last line.. this will add a space after the line in your output.  I took three hours to find and fix this bug.