|
qdfeng
新手上路
积分 8
发帖 7
注册 2010-6-12
状态 离线
|
『楼 主』:
【求助】请教一下如何从一组字符串中提取几个关键字
我提取交换机端口光功率生成txt文件,其内容如下:
GigabitEthernet1/0/0 current state : UP
Rx Power: -4.85dBm, Tx Power: -4.99dBm
GigabitEthernet1/0/1 current state : UP
Rx Power: -5.73dBm, Tx Power: -5.27dBm
GigabitEthernet1/0/2 current state : UP
Rx Power: -4.93dBm, Tx Power: -4.94dBm
GigabitEthernet1/0/3 current state : UP
Rx Power: -4.17dBm, Tx Power: -4.99dBm
GigabitEthernet1/0/4 current state : UP
Rx Power: -5.23dBm, Tx Power: -5.07dBm
我想生成如下格式的txt文件,各位高手应该怎么写?谢谢哈
GigabitEthernet1/0/1 Rx Power: -5.73dBm
GigabitEthernet1/0/2 Rx Power: -4.93dBm
GigabitEthernet1/0/3 Rx Power: -4.17dBm
GigabitEthernet1/0/4 Rx Power: -5.23dBm
|
|
2010-6-15 19:30 |
|
|
Hanyeguxing
银牌会员
正在学习中的菜鸟...
积分 1039
发帖 897
注册 2009-3-1 来自 在地狱中仰望天堂
状态 离线
|
『第
2 楼』:
@echo off&setlocal enabledelayedexpansion
(for /F "skip=2 delims=Cc," %%a in (1.txt) do set "a=%%a"&if /i "!a:~0,1!"=="G" (set/p=%%a<nul) else echo.%%a)>2.txt 或:
@echo off&setlocal enabledelayedexpansion
(for /F "delims=Cc," %%a in (1.txt) do (set "a=%%a"&set/a n+=1&if !n! gtr 2 if /i "!a:~0,1!"=="G" (set/p=%%a<nul) else echo.%%a))>2.txt 或:
@echo off&setlocal enabledelayedexpansion
(for /F "skip=2 tokens=1-3 delims=, " %%a in (1.txt) do set "a=%%a"&if /i "!a:~0,1!"=="G" (set/p=%%a<nul) else echo.%%a %%b %%c)>2.txt 或:
@echo off&setlocal enabledelayedexpansion
(for /F "tokens=1-3 delims=, " %%a in (1.txt) do set "a=%%a"&set/a n+=1&if !n! gtr 2 if /i "!a:~0,1!"=="G" (set/p=%%a<nul) else echo.%%a %%b %%c)>2.txt [ Last edited by Hanyeguxing on 2010-6-15 at 20:02 ]
|
批处理之家 http://bbs.bathome.net/forum-5-1.html |
|
2010-6-15 19:43 |
|
|
qdfeng
新手上路
积分 8
发帖 7
注册 2010-6-12
状态 离线
|
|
2010-6-15 20:23 |
|
|
qdfeng
新手上路
积分 8
发帖 7
注册 2010-6-12
状态 离线
|
『第
4 楼』:
再请教一下如果字符串中还存在pos这个关键字我如何提取啊?
GigabitEthernet1/0/3 current state : UP
Rx Power: -4.17dBm, Tx Power: -4.99dBm
GigabitEthernet1/0/4 current state : UP
Rx Power: -5.23dBm, Tx Power: -5.07dBm
Pos1/0/1 current state : UP
Rx Power: -5.25dBm, Tx Power: -4.26dBm
生成结果为:
GigabitEthernet1/0/3 Rx Power: -4.17dBm
GigabitEthernet1/0/4 Rx Power: -5.23dBm
Pos1/0/1 Rx Power: -5.25dBm
|
|
2010-6-15 21:10 |
|
|
Hanyeguxing
银牌会员
正在学习中的菜鸟...
积分 1039
发帖 897
注册 2009-3-1 来自 在地狱中仰望天堂
状态 离线
|
『第
5 楼』:
@echo off&setlocal enabledelayedexpansion
(for /F "tokens=1-3 delims=, " %%a in (1.txt) do (set "a=%%a"
if not defined n if /i "!a:~0,1!"=="R" echo.!a! %%b %%c
if /i "!a:~0,1!"=="G" call:n,"!a!"
if /i "!a:~0,1!"=="P" call:n,"!a!"))>2.txt
pause&exit
:n
set a=%~1
if not "!a:~-2!"=="/0" (set n=&set/p=!a! <nul) else set n== [ Last edited by Hanyeguxing on 2010-6-15 at 23:13 ]
|
批处理之家 http://bbs.bathome.net/forum-5-1.html |
|
2010-6-15 23:11 |
|
|
qdfeng
新手上路
积分 8
发帖 7
注册 2010-6-12
状态 离线
|
『第
6 楼』:
呵呵,谢谢Hanyeguxing老大哈!!!!
|
|
2010-6-16 10:13 |
|