duncanb7
asked on
find a string in each line in a file for Window batch shell script
Dear Expert,
I've one file called "junk.txt" in which I would like to replace Hostname and PortNumber
string with new value using window batch shell script , but I am spending more a few
hour in google, and still can not solve why I can not echo str variabie which
is always empty from following script code, Could you help on this, how to find
a string in string and replace with the new value. And the string addtion is "+" psosible ?
set newip="203.1.123.342"
set newport="00001779"
for /F "tokens=*" %%i in (junk.txt) do set str=%%i & echo %str% & if (%str:~1,9)=="HostName") str='"HostName"="'+'"+newi p+'""
Please advise
Duncan
junk.txt file
=============
I've one file called "junk.txt" in which I would like to replace Hostname and PortNumber
string with new value using window batch shell script , but I am spending more a few
hour in google, and still can not solve why I can not echo str variabie which
is always empty from following script code, Could you help on this, how to find
a string in string and replace with the new value. And the string addtion is "+" psosible ?
set newip="203.1.123.342"
set newport="00001779"
for /F "tokens=*" %%i in (junk.txt) do set str=%%i & echo %str% & if (%str:~1,9)=="HostName") str='"HostName"="'+'"+newi
Please advise
Duncan
junk.txt file
=============
"Present"=dword:00000001
"HostName"="217.76.12.127"
"Protocol"="ssh"
"PortNumber"=dword:00001771
"CloseOnExit"=dword:00000001
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for all of your rely.
I tried obda 's code in one time, it works as I expect
and dragon-it, thanks for your code, I tried it that seems not working
even review it many times and check all correct file typing and path.
The output junk.txt is same as before
Thanks for your attached link for the subject
Have a nice
Duncan
I tried obda 's code in one time, it works as I expect
and dragon-it, thanks for your code, I tried it that seems not working
even review it many times and check all correct file typing and path.
The output junk.txt is same as before
Thanks for your attached link for the subject
Have a nice
Duncan
Ok, no problem. Worked for me here but then copy/pasted wrong version, line 19 should have been
echo %%i=!value!
Steve
echo %%i=!value!
Steve
Steve