本帖最后由 yujw668 于 2018-9-30 12:38 编辑
A文本内容- 192.168.0.2 0111.5777.132
- 192.168.0.4 0111.5515.333
- 192.168.0.5 0114.5555.334
- 192.168.0.6 0113.4555.335
- 192.168.0.7 0111.5555.336
- 192.168.0.8 0166.5557.338
- 192.168.0.9 0121.5555.393
- 192.168.0.13 0111.5555.300
- 192.168.0.17 0119.5555.311
- 192.168.0.19 0111.3555.333
- 192.168.0.20 0111.2555.321
- 192.168.0.22 0111.5512.133
- 192.168.0.23 0111.9555.333
- 192.168.0.25 0112.6525.377
- 192.168.0.26 0188.5500.988
- 192.168.0.27 0111.5789.311
- 192.168.0.29 0131.51b5.314
- 192.168.0.30 0011.55C5.333
- 192.168.0.32 0101.2531.333
- 192.168.0.33 0110.5511.332
- 192.168.0.34 0111.5444.354
- 192.168.0.35 0111.5543.333
- 192.168.0.36 0111.5555.157
- 192.168.0.40 0122.5555.401
- 192.168.0.41 0111.5588.123
复制代码 B文本内容- 192.168.0.2 1111.1331.1111.2226 mac
- 192.168.0.4 1111.1111.1111.2228 windows
- 192.168.0.5 linux
- 192.168.0.6 7113.1661.1111.222 linux
- 192.168.0.9 513.1361.1111.2222 windows
- 192.168.0.12 windows
- 192.168.0.23 9613.1651.1111.2321 mac
- 192.168.0.28 mac
- 192.168.0.37 lixux
- 192.168.0.40 lixux
复制代码 C文本- 192.168.0.2 0111.5777.132 2mac
- 192.168.0.4 0111.5515.333 2windows
- 192.168.0.5 0114.5555.334 1linux
- 192.168.0.6 0113.4555.335 2linux
- 192.168.0.9 0121.5555.393 2windows
- 192.168.0.12 3windows
- 192.168.0.23 0111.9555.333 2mac
- 192.168.0.28 3mac
- 192.168.0.37 3lixux
- 192.168.0.40 0122.5555.401 1lixux
复制代码
- @echo off
- setlocal ENABLEDELAYEDEXPANSION
- for /f "tokens=1,2" %%a in (A.txt) do set "%%a=%%b"
- (for /f "tokens=1-3" %%a in (B.txt) do (
- if defined %%a (if "%%c"=="" (set "str=1%%b") else set "str=2%%c") else (if "%%c"=="" (set "str= 3%%b") else set "str=4%%c")
- echo %%a !%%a! !str!)
- )>C.txt
- pause
复制代码 我又重新编辑了一下文本,中间都是用TAB分割
想请问下,就是在取值的时候生成的C文本里丢弃带有空的行该怎么处理呢。也就是说192.168.0.12 192.168.0.28 192.168.0.40 对应的相应的行都丢弃。- @echo off
- setlocal ENABLEDELAYEDEXPANSION
- for /f "tokens=1,2" %%A in (A.txt) do set "%%A=%%B"
- (for /f "tokens=1-3" %%A in (B.txt) do (
-
- if defined %%A echo %%A !%%A! %%C)
-
-
- )>C.txt
- pause
复制代码 我这么定义,但是第三列又取不出来了。。。 |