批处理脚本替换线的.ini [英] Batch Script to replace line in an .ini
问题描述
请原谅我。我是一个完整的小白。
Please excuse me. I'm a complete noob.
我有1 ini文件中,只有1个IP地址和版本number.in格式为:
I have 1 ini file with only 1 IP address and a version number.in this format:
xxx.xxx.xxx.xxx
abcde
我有3个总IP的,我需要适应。
我希望创建一个批处理脚本会询问用户的位置,他们想连接(每个位置将对应一个IP地址)。
I have 3 total IP's that I need to accommodate. I'm looking to create a batch script that will ask a user for a location they'd like to connect to (each location would correspond to an IP address).
因此,例如:NY = 10.0.0.0 DC = 20.0.0.0 LA = 30.0.0.0
So for example: NY = 10.0.0.0 DC = 20.0.0.0 LA = 30.0.0.0
该批处理会说:你想去哪里连接?1 = NY,2 = DC,3 = LA
当用户为NY选择1时,脚本将搜索.ini文件(它总是在相同的位置C:\\样品),并更改IP到正确的(10.0.0.0)。
这将有类似的输出你现在连接到纽约!
The batch would say "Where do you want to connect? 1= NY, 2= DC, 3= LA" When a user selects 1 for "NY", the script will search the .ini file (which is always in the same location c:\sample) and change the IP to the correct one (10.0.0.0). It would have an output of something like "You're now connected to NY!"
当用户选择DC,该脚本将搜索.ini文件并将其更改为20.0.0.0 etc.I'm能够做一个简单的查找/替换脚本,但只有2个IP地址,我有做一个这是相当不方便的每个位置。
When a user selects "DC", the script will search the .ini file and change it to 20.0.0.0 etc.I'm able to do a simple find/replace script, but only with 2 IPs, and I had to make one for each location which was rather inconvenient.
任何帮助或指导多AP preciated!
Any help or guidance is much appreciated!
推荐答案
本例将:
- 要求用户输入NY,DC或LA;
- 创建x.tmp这是x.ini副本,替换所有xxx.xxx ...用争论;
- 与x.tmp替换exisitng x.ini;
code:
@Echo Off
:Begin
If Exist c:\sample\x.tmp Del c:\sample\x.tmp
Set /P "var=Choose location (NY, DC, LA):"
If /I "%var%"=="NY" Call :ReplaceIP 10.0.0.0
If /I "%var%"=="DC" Call :ReplaceIP 20.0.0.0
If /I "%var%"=="LA" Call :ReplaceIP 30.0.0.0
If Exist c:\sample\x.tmp (
Move /Y c:\sample\x.tmp c:\sample\x.ini 1>Nul
Echo Success!
) Else (
Echo Invalid option!
)
Pause
GoTo :Begin
:ReplaceIP
For /F "Tokens=1,2,3,4 Delims=." %%i In (c:\sample\x.ini) do If %%j.==. (
Echo %%i >> c:\sample\x.tmp
) Else (
Echo %1 >> c:\sample\x.tmp
)
GoTo :EOF
这篇关于批处理脚本替换线的.ini的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!