Need help locating a line in text file and replacing it
Posted: 14 Mar 2011 23:32
Hi all,
I'm needing a push in the right direct for getting substring of a variable with in a FOR and am new to DOS batch scripting. I am creating a batch file for editing an ini file and not having the luxury of using c++ or java for this need. I am trying to locate a line in a file beginning with "XYZ=..." (to later save it back) and storing the line as a variable while replacing the line with "XYZ=".
My code is as follows:
this pasted is just one of many attempts to get the substring of each to echo out for verifying a value is there.
seems that if the value to substring is static then it will return what I am expecting, but getting the substring of a variable is returning nothing " ".
I am basically intending to loop through each line and find the substring, and then replace that line (saving to put it back after batch calls an exe). I've been chasing my tail on this all day and appreciate any assistance.
Thanks for your time,
Geoff-
I'm needing a push in the right direct for getting substring of a variable with in a FOR and am new to DOS batch scripting. I am creating a batch file for editing an ini file and not having the luxury of using c++ or java for this need. I am trying to locate a line in a file beginning with "XYZ=..." (to later save it back) and storing the line as a variable while replacing the line with "XYZ=".
My code is as follows:
Code: Select all
@echo off
set str=teststuff
echo.%str%
set str=%str:~0,4%
echo.%str%
SETLOCAL=ENABLEDELAYEDEXPANSION
rename c:\lotus\notes\notes.ini notes.tmp
for /f %%a in (c:\lotus\notes\notes.tmp) do (
set foo=%%a
set substr=%%a:~0,11%
echo.substr
if substr=="KeyFileName=" set foo=""
echo.%foo% >> c:\lotus\notes\notes.ini)
this pasted is just one of many attempts to get the substring of each to echo out for verifying a value is there.
seems that if the value to substring is static then it will return what I am expecting, but getting the substring of a variable is returning nothing " ".
I am basically intending to loop through each line and find the substring, and then replace that line (saving to put it back after batch calls an exe). I've been chasing my tail on this all day and appreciate any assistance.
Thanks for your time,
Geoff-