标题: [文本处理] [已解决]批处理怎样查找文本不定行指定内容并输出? [打印本页]
作者: wangyangweb 时间: 2013-6-10 11:19 标题: [已解决]批处理怎样查找文本不定行指定内容并输出?
要查找的文本内容片断:
Basic:
User access index : 854
State : Used
User name : zhangsan
User access status1 : OK
User access status2 : OK
User access PeVlan/CeVlan : 2112/1120
User-Group : -
AAA:
Action flag : Idle
Authen state : Authed
Author state : Idle
Basic:
User access index : 231
State : Used
User name : huangli
User access status1 : OK
User access status2 : OK
User access PeVlan/CeVlan : 2372/6490
User-Group : -
AAA:
Action flag : Idle
Authen state : Authed
Author state : Idle
Basic:
User access index : 251
State : Used
User name : liliang
User access status1 : OK
User access status2 : OK
User access PeVlan/CeVlan : 3111/2643
User-Group : -
AAA:
Action flag : Idle
Authen state : Authed
Author state : Idle
Basic:
User access index : 104
State : Used
User name : sunqian
User access status1 : OK
User access status2 : OK
User access PeVlan/CeVlan : 1128/3243
User-Group : -
AAA:
Action flag : Idle
Authen state : Authed
Author state : Idle
想要得到的结果(输出到csv表格文件):
zhangsan,2112/1120
huangli,2372/6490
liliang,3111/2643
sunqian,1128/3243
即:查找User name和User access PeVlan/CeVlan冒号后面的内容,成对输出(Basic和AAA块成对出现属于一个文本域)
小弟只能单行处理,资历较浅,无法成对输出,帮小弟一把,谢啦老大
作者: terse 时间: 2013-6-10 12:17
- @echo off&setlocal enabledelayedexpansion
- set filename="data.txt"
- set "find=findstr /ic:"User name" /c:"User access PeVlan/CeVlan""
- for /f "tokens=1* delims=:" %%i in ('%find% %filename%')do (
- if defined str (
- echo !str!,%%j
- set str=
- ) else set str=%%j
- )
- pause
复制代码
作者: wangyangweb 时间: 2013-6-10 13:41
回复 2# terse
成功啦 感谢老大帮忙,我再好好研究研究你的代码
欢迎光临 批处理之家 (http://www.bathome.net/) |
Powered by Discuz! 7.2 |