[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖

[文本处理] 批处理如何从文本中提取出指定字符串中的一个数值?

本帖最后由 pcl_test 于 2016-5-17 19:57 编辑

文件client.log内容截取如下:
Tue May 17 14:31:15 2016 open_tun, tt->ipv6=1
Tue May 17 14:31:15 2016 TAP-WIN32 device [以太网 2] opened: \\.\Global\{CC24EDA2-5504-4FF7-B05F-D237B425573E}.tap
Tue May 17 14:31:15 2016 TAP-Windows Driver Version 9.21
Tue May 17 14:31:15 2016 Set TAP-Windows TUN subnet mode network/local/netmask = 169.254.0.0/169.254.0.5/255.255.0.0
{CC24EDA2-5504-4FF7-B05F-D237B425573E} [DHCP-serv: 169.254.255.254, lease-time: 31536000]
Tue May 17 14:31:15 2016 Successful ARP Flush on interface [27] {CC24EDA2-5504-4FF7-B05F-D237B425573E}
Tue May 17 14:31:20 2016 TEST ROUTES: 0/0 succeeded len=0 ret=1 a=0 u/d=up
Tue May 17 14:31:20 2016 add_route_ipv6(2000::/3 -> 240c:f:1:6000::1 metric -1) dev 以太网 2
Tue May 17 14:31:20 2016 C:\Windows\system32\netsh.exe interface ipv6 add route 2000::/3 interface=27 fe80::8
Tue May 17 14:31:20 2016 Initialization Sequence Completed
Tue May 17 14:31:20 2016 MANAGEMENT: >STATE:1463466680,CONNECTED,SUCCESS,169.254.0.5,192.168.1.223
Tue May 17 14:31:23 2016 delete_route_ipv6(2000::/3)
其中红色部分是在文件中唯一的,我想把[]之间的数值取出来放在一个变量中,此处为27.
请问脚本应该如何写呢?

多谢各位大侠!
1

评分人数

  1. @echo off
  2. for /f "tokens=2 delims=[]" %%a in ('findstr /c:"Successful ARP Flush on interface" client.log') do echo.%%a
  3. pause
复制代码

TOP

  1. @echo off
  2. for /f "tokens=2 delims=[]" %%i in ('type "client.log" ^| findstr /c:"Successful ARP Flush on interface"') do (
  3.     set str=%%i
  4. )
  5. echo,%str%
  6. pause
复制代码
Talk is cheap. Show me the code.
没事不要瞎扯淡,有能耐就把代码贴出来给我看。

TOP

返回列表