开发者

VB script + change the first value of the first param in txt file

how to replace only the first value of MODE parameter in the bash script from "ON" to "OFF" by VB script?

the bash script location: C:\folder_scripts\script.bash

THX

Yael

the bas开发者_如何学Goh script (txt file):

#!/bin/bash

MODE=ON


if [[ $MODE = ON ]]

then

 echo "the machine is on line"

elif  [[ $MODE = OFF ]]

 echo "the machine is OFF line"

fi


Replace has a Count and Start argument, setting Count to 1 will replace the first occurance:

Set fs = CreateObject("Scripting.FileSystemObject")
sf = "C:\folder_scripts\script.bash"

Set f = fs.OpenTextFile(sf, 1) ''1=for reading
s = f.ReadAll
s = Replace(s, "MODE=On", "MODE=Off",1,1)
f.Close
Set f = fs.OpenTextFile(sf, 2) ''2=ForWriting
f.Write s
f.Close

If the text could vary, for example, in the number of spaces between MODE and equals sign, you can read the text line by line (s=f.ReadLine) until you find the first line in which MODE occurs.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜