Hi Team,
I need the script/code by which I can do the find & replace in the file & save it with different name using command prompt. For example :
I have the source file "RUN.bat" with the contents
:: *** ACSD -
:: del "%A%"\ACSD_error
:: del "%Ap%"\ACSD_audit
Here I would like to replace all the ACSD with XYZ and create the new file "New.bat" witht he contents
:: *** XYZ -
:: del "%A%"\XYZ_error
:: del "%Ap%"\XYZ_audit
Regards,
Yaduvanshi.
Find & Replace in a file using DOS.
Moderator: DosItHelp
Re: Find & Replace in a file using DOS.
Untested:
@echo off
call sar.bat "run.bat" "new.bat" "ASCD" "XYZ"
Code: Select all
:: sar.bat
@echo off
if "%~3"=="" (
echo.Search and replace
echo Syntax:
echo %0 "filein.txt" "fileout.ext" "regex" "replace_text" [first]
echo.
echo. if [first] is present only the first occurrence is changed
goto :EOF
)
if "%~5"=="" (set global=true) else (set global=false)
set s=regex.replace(wscript.stdin.readall,"%~4")
>_.vbs echo set regex=new regexp
>>_.vbs echo regex.global=%global%
>>_.vbs echo regEx.IgnoreCase=True
>>_.vbs echo regex.pattern="%~3"
>>_.vbs echo wscript.stdOut.write %s%
cscript /nologo _.vbs <"%~1" >"%~2"
del _.vbs
-
- Posts: 4
- Joined: 02 May 2012 04:03
Re: Find & Replace in a file using DOS.
foxidrive wrote:Untested:@echo off
call sar.bat "run.bat" "new.bat" "ASCD" "XYZ"Code: Select all
:: sar.bat
@echo off
if "%~3"=="" (
echo.Search and replace
echo Syntax:
echo %0 "filein.txt" "fileout.ext" "regex" "replace_text" [first]
echo.
echo. if [first] is present only the first occurrence is changed
goto :EOF
)
if "%~5"=="" (set global=true) else (set global=false)
set s=regex.replace(wscript.stdin.readall,"%~4")
>_.vbs echo set regex=new regexp
>>_.vbs echo regex.global=%global%
>>_.vbs echo regEx.IgnoreCase=True
>>_.vbs echo regex.pattern="%~3"
>>_.vbs echo wscript.stdOut.write %s%
cscript /nologo _.vbs <"%~1" >"%~2"
del _.vbs
I am getting the error " 'cscript' is not recognized as an internal or external command, operable program or batch file."
Please suggest.
Regards,
Yaduvanshi.
Re: Find & Replace in a file using DOS.
What version of Windows are you using? Has the PATH variable been modified by you?
I have this in XP:
c:\WINDOWS\system32\cscript.exe
I have this in XP:
c:\WINDOWS\system32\cscript.exe
-
- Posts: 4
- Joined: 02 May 2012 04:03
Re: Find & Replace in a file using DOS.
Tha path is same for me as well...I have checked.
I am using Windows7 Enterprise Edition 32 bit OS.
I am using Windows7 Enterprise Edition 32 bit OS.
Re: Find & Replace in a file using DOS.
open a cmd prompt and type
See what you get. It is possible that you need to run it as Admin.
Code: Select all
cscript /?
See what you get. It is possible that you need to run it as Admin.