标题: [文本处理] [分享]批处理逐列合并两个文件 [打印本页]
作者: Batcher 时间: 2019-5-17 09:08 标题: [分享]批处理逐列合并两个文件
【问题】vpndown插到vpnup前面怎操作?
vpndown.bat
delete 1.0.1.0
delete 1.0.2.0
delete 1.0.8.0
delete 1.0.32.0
delete 1.1.0.0
delete 1.1.2.0
delete 1.1.4.0
delete 1.1.8.0
delete 1.1.9.0
vpnup.bat
mask 255.255.252.0 default METRIC default IF default
mask 255.255.252.0 default METRIC default IF default
mask 255.255.252.0 default METRIC default IF default
mask 255.224.0.0 default METRIC default IF default
mask 255.240.0.0 default METRIC default IF default
mask 255.252.0.0 default METRIC default IF default
mask 255.254.0.0 default METRIC default IF default
mask 255.255.128.0 default METRIC default IF default
mask 255.255.128.0 default METRIC default IF default
mask 255.254.0.0 default METRIC default IF default
mask 255.252.0.0 default METRIC default IF default
mask 255.254.0.0 default METRIC default IF default
mask 255.240.0.0 default METRIC default IF default
【代码】- @echo off
- setlocal enabledelayedexpansion
- (for /f "delims=" %%i in ('type "vpndown.bat"') do (
- set /p str=
- echo %%i !str!
- ))<"vpnup.bat" >"合并结果.bat"
复制代码
作者: syscca 时间: 2019-5-17 16:43
本帖最后由 syscca 于 2019-5-17 16:55 编辑
vpndown.bat原数据- @echo off
- route delete 1.0.1.0
- route delete 1.0.2.0
- route delete 1.0.8.0
- route delete 1.0.32.0
- route delete 1.1.0.0
- route delete 1.1.2.0
- route delete 1.1.4.0
- route delete 1.1.8.0
- route delete 1.1.9.0
复制代码
处理vpndown.bat做成del.txt这样的数据但mask后面要对上add.txt的数据- delete 1.0.1.0 mask 255.255.255.0 default METRIC default IF default
- delete 1.0.2.0 mask 255.255.254.0 default METRIC default IF default
- delete 1.0.8.0 mask 255.255.248.0 default METRIC default IF default
- delete 1.0.32.0 mask 255.255.224.0 default METRIC default IF default
- delete 1.1.0.0 mask 255.255.255.0 default METRIC default IF default
- delete 1.1.2.0 mask 255.255.254.0 default METRIC default IF default
- delete 1.1.4.0 mask 255.255.252.0 default METRIC default IF default
- delete 1.1.8.0 mask 255.255.255.0 default METRIC default IF default
- delete 1.1.9.0 mask 255.255.255.0 default METRIC default IF default
复制代码
vpnup.bat原数据- @echo off
- for /F "tokens=3" %%* in ('route print ^| findstr "\<0.0.0.0\>"') do set "gw=%%*"
-
-
- ipconfig /flushdns
-
- route add 1.0.1.0 mask 255.255.255.0 %gw% metric 5
- route add 1.0.2.0 mask 255.255.254.0 %gw% metric 5
- route add 1.0.8.0 mask 255.255.248.0 %gw% metric 5
- route add 1.0.32.0 mask 255.255.224.0 %gw% metric 5
- route add 1.1.0.0 mask 255.255.255.0 %gw% metric 5
- route add 1.1.2.0 mask 255.255.254.0 %gw% metric 5
- route add 1.1.4.0 mask 255.255.252.0 %gw% metric 5
- route add 1.1.8.0 mask 255.255.255.0 %gw% metric 5
- route add 1.1.9.0 mask 255.255.255.0 %gw% metric 5
复制代码
处理vpnup.bat做成add.txt这样的数据- add 1.0.1.0 mask 255.255.255.0 default METRIC default IF default
- add 1.0.2.0 mask 255.255.254.0 default METRIC default IF default
- add 1.0.8.0 mask 255.255.248.0 default METRIC default IF default
- add 1.0.32.0 mask 255.255.224.0 default METRIC default IF default
- add 1.1.0.0 mask 255.255.255.0 default METRIC default IF default
- add 1.1.2.0 mask 255.255.254.0 default METRIC default IF default
- add 1.1.4.0 mask 255.255.252.0 default METRIC default IF default
- add 1.1.8.0 mask 255.255.255.0 default METRIC default IF default
- add 1.1.9.0 mask 255.255.255.0 default METRIC default IF default
复制代码
作者: Batcher 时间: 2019-5-17 16:51
回复 2# syscca
先说第一个需求,del.txt里面的第4列子网掩码是根据什么规律出来的?
作者: Batcher 时间: 2019-5-17 16:57
处理vpnup.bat- @echo off
- (for /f "tokens=2-5" %%a in ('findstr /c:"route add" "vpnup.bat"') do (
- echo %%a %%b %%c %%d default METRIC default IF default
- ))>"add.txt"
复制代码
作者: syscca 时间: 2019-5-17 16:59
我用PY扫描出来的。https://github.com/fivesheep/chnroutes回复 3# Batcher
作者: syscca 时间: 2019-5-17 17:17
规律就是对上add.txt的数据回复 3# Batcher
作者: Batcher 时间: 2019-5-17 18:15
回复 6# syscca
你先试试4楼代码生成的add.txt是否正确?
作者: Batcher 时间: 2019-5-17 18:21
如果4楼代码生成的add.txt是正确的,那么可以这样生成del.txt- @echo off
- (for /f "tokens=1*" %%a in ('type "add.txt"') do (
- echo delete %%b
- ))>"del.txt"
复制代码
作者: syscca 时间: 2019-5-17 18:51
谢谢回复 8# Batcher
欢迎光临 批处理之家 (http://www.bathome.net/) |
Powered by Discuz! 7.2 |