问题
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