Batch/VBS: asking for user input and with his data replace a string in a existent text file

梦想与她 提交于 2020-01-06 08:21:17

问题


I need a vbs or batch to ask to user a value and after, put this value in a text file where I've to replace an existent value...

Currently, with a batch file, I can get user input and put it into a variable, but I can't find any feature to find a "part of a numeric string" (ip address) in to text file and replace it.

ES:

Let's say that the text file is "hosts.txt":

172.16.16.1 serverA

172.16. are constant value, I've to replace only the other 2 octet "16.1"...

All tools that I know can't use "*" symbol in the search string options...

I can remove all ip address value or full line, but in this case I've to know the last value of ip address for find it and then add name record at the end of new value...

I cannot install anything into the clients, they are not under my administration.

Can you help me please?

Thanks, Robby.


回答1:


for /f "tokens=1-4* delims=. " %A in (hosts.txt) do Echo %A.%B.newnum.newnum %E

the four octets are in %A, %B, %C, & %D and %E has servername

%A becomes %%A in a batch.



来源:https://stackoverflow.com/questions/25453845/batch-vbs-asking-for-user-input-and-with-his-data-replace-a-string-in-a-existen

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!