中国DOS联盟论坛

China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --
Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
Guest | Log in | Register | Members | Search | China DOS Union
中国DOS联盟论坛
The time now is 2026-08-09 01:09
47,811 topics / 349,895 posts / today 0 new / 48,253 members
DOS批处理 & 脚本技术(批处理室) » Question about getting a specified position in text
Printable Version  728 / 7
Floor1 andison625 Posted 2008-05-30 17:44
初级用户 Posts 36 Credits 70
I'm new here, and I'm not familiar with some problems and commands yet. I hope the experts can give me some pointers.. thanks

I need to find out my own IP, then based on that IP, find the corresponding server address from a data text file.
And it has to be set automatically....

Here is my line of thought, and the part I can't figure out:

There is a data address for an IP stored in a document.. the format is as follows:
10.248.52.63 10.248.31.15 ......
10.248.52.64 10.248.31.16 ......
10.248.52.65 10.248.31.16 ......
10.248.52.166 10.248.31.16 ......
10.248.52.67 10.248.31.32 ......
10.248.52.168 10.248.31.32 ......
10.248.52.69 10.248.31.32 ......
10.248.52.170 10.248.31.33 ......

Then get my own IP and save it into the myip.txt document
for /f "tokens=15" %%i in ('ipconfig ^| find /i "ip address"' do set ip=%%i
echo Your IP is:%ip%
( find "%ip%" < icdconfig.txt ) >myip.txt ::

After that there is one line of data in myip.txt, such as:
10.248.52.63 10.248.31.15 ......

These data were converted from EXCLE. The ".........." at the back are the remaining several server IP addresses... the two IP addresses are separated by a Tab.
What I need is to get the last segment of 10.248.31.15 in this IP (the number 15)
and store it in a variable for later use

The problem is here: how can I get the number 15 and store it into a variable
for me to call again?
I tried using for and findstr, but neither can specify this position.......

Please help me.....

[ Last edited by andison625 on 2008-6-1 at 09:52 AM ]
Floor2 bat-zw Posted 2008-05-30 18:12
金牌会员 Posts 1,276 Credits 3,105
After reading the OP's description, I cried. I've studied Chinese for so many years, yet I still can't understand what the OP is trying to say. Looks like I need to go study Chinese for a few more years.
Floor3 26933062 Posted 2008-05-30 18:19
银牌会员 Posts 879 Credits 2,268
Originally posted by zw19750516 at 2008-5-30 18:12:
After reading the OP's description, I cried. I've studied Chinese for so many years, yet I still can't understand what the OP is trying to say. Looks like I need to go study Chinese for a few more years.

Hahaha, I thought I was the only one who couldn't understand it because I haven't read many books, but turns out you can't understand it either。。。。!
Floor4 lxmxn Posted 2008-05-30 18:34
版主 Posts 4,938 Credits 11,386
What the OP seems to mean is:
Floor5 andison625 Posted 2008-06-01 09:40
初级用户 Posts 36 Credits 70
What I mean is... get a specified value from text.
192.168.0.12 10.248.31.15

What I want is the last segment of the second IP address (the number 15), and assign it to a variable for me to use..
Floor6 andison625 Posted 2008-06-01 09:49
初级用户 Posts 36 Credits 70
Thanks, moderator lxmxn...
for /f "tokens=2" %%a in (myip.txt) do @(for /f "delims=. tokens=4" %%b in ("%%a") do @echo.%%b)

This method found the position I wanted.

But I still don't understand the usage of for very well, it seems quite different from the languages I've learned
Does the forum have any batch programming tutorial like CHM available for download?
I really want to learn batch programming well......
Floor7 liminghack Posted 2008-06-01 10:02
初级用户 Posts 25 Credits 51 From 学校
Not sure why, but after reading the OP's description, my head feels a bit dizzy! What exactly is it?
Floor8 joyn Posted 2008-06-01 19:05
中级用户 Posts 105 Credits 280 From 广西
@echo off&&setlocal ENABLEDELAYEDEXPANSION
for /f "tokens=1*" %%i in (myip.txt) do (
if "%%i"=="192.168.0.12" (
echo corresponding server IP: %%j&&set ips=%%j
for /f "delims=. tokens=1-4 " %%a in ("!ips!") do (
set ipxs=%%d&echo last part of the corresponding server IP: !ipxs!
)))




Is this what you want to achieve?
Replace the variables yourself..... not sure whether this is what you mean


[ Last edited by joyn on 2008-6-1 at 07:10 PM ]
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023