标题: [文本处理] 批处理如何从文本中提取出指定字符串中的一个数值? [打印本页]
作者: luxxsys 时间: 2016-5-17 15:24 标题: 批处理如何从文本中提取出指定字符串中的一个数值?
本帖最后由 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.
请问脚本应该如何写呢?
多谢各位大侠!
作者: flyinnet9 时间: 2016-5-17 17:38
- @echo off
- for /f "tokens=2 delims=[]" %%a in ('findstr /c:"Successful ARP Flush on interface" client.log') do echo.%%a
- pause
复制代码
作者: gawk 时间: 2016-5-18 08:29
- @echo off
- for /f "tokens=2 delims=[]" %%i in ('type "client.log" ^| findstr /c:"Successful ARP Flush on interface"') do (
- set str=%%i
- )
- echo,%str%
- pause
复制代码
欢迎光临 批处理之家 (http://bbs.bathome.net/) |
Powered by Discuz! 7.2 |