Author
MS DOS COMMAND HELP (Read 565 times)
No Image
Post: 8
MS DOS COMMAND HELP
on: Monday 08 June, 2009, 05:22:10 AM

i want to find and replace text in a file using DOS commands..
can anyone help me with that..
i need it urgently..

thanks
ayushi

No Image
Post: 12
Re: MS DOS COMMAND HELP
on: Tuesday 09 June, 2009, 12:41:14 AM

[code]@echo off
SETLOCAL ENABLEEXTENSIONS
SETLOCAL DISABLEDELAYEDEXPANSION

::syntax: replace.bat OldStr NewStr File>NewFile
::          OldStr [in] - string to be replaced
::          NewStr [in] - string to replace with
::          File  [in] - file to be parsed
if "%*"=="" findstr "^::" "%~f0"&GOTO:EOF
for /f "tokens=1,* delims=]" %%A in ('"type %3|find /n /v """') do (
    set "line=%%B"
    if defined line (
        call set "line=echo.%%line:%~1=%~2%%"
        for /f "delims=" %%X in ('"echo."%%line%%""') do %%~X
    ) ELSE echo.
)[/code]

Copy the above text into a blank file and save it as "replace.bat". Then type "replace oldword newstr oldfile>newfile" in command prompt(without double quote). for e.g. replace "tech" "technology" file1.txt>file2.txt