免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1517 | 回复: 3
打印 上一主题 下一主题

[文本处理] 找文件内容 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2015-09-08 15:02 |只看该作者 |倒序浏览
请问怎么把一个文本里包含一行"Msg xxx,  Level xx, State xx:" 的找出来呢?


Msg 2812, Level 16, State 5:
Msg 234
Server 'test', Line 1:
Stored procedure 'sphsdf' not found. Specify owner.objectname or use sp_help to check whether the object exists (sp_help may produce lots of output).
to check whether the object exists (sp_help may
to check whether the object exists (sp_help may
Msg 28122, Level 122, State 543:

论坛徽章:
54
2015亚冠之德黑兰石油
日期:2015-07-07 13:00:1615-16赛季CBA联赛之深圳
日期:2016-03-31 09:03:5415-16赛季CBA联赛之辽宁
日期:2016-05-09 20:38:15程序设计版块每日发帖之星
日期:2016-05-12 06:20:0015-16赛季CBA联赛之四川
日期:2016-05-13 15:19:4715-16赛季CBA联赛之福建
日期:2016-05-15 20:24:34每日论坛发贴之星
日期:2016-05-16 06:20:0015-16赛季CBA联赛之吉林
日期:2016-05-26 11:49:4715-16赛季CBA联赛之广东
日期:2016-05-26 13:49:18极客徽章
日期:2016-12-07 14:05:2315-16赛季CBA联赛之广夏
日期:2016-12-20 17:33:532017金鸡报晓
日期:2017-01-10 15:19:56
2 [报告]
发表于 2015-09-08 15:29 |只看该作者
powershell
  1. Get-Content .\c.txt | where {$_ -match "^Msg \d+, Level \d+, State \d+:$"}
  2. Msg 2812, Level 16, State 5:
  3. Msg 28122, Level 122, State 543:
复制代码

论坛徽章:
145
技术图书徽章
日期:2013-10-01 15:32:13戌狗
日期:2013-10-25 13:31:35金牛座
日期:2013-11-04 16:22:07子鼠
日期:2013-11-18 18:48:57白羊座
日期:2013-11-29 10:09:11狮子座
日期:2013-12-12 09:57:42白羊座
日期:2013-12-24 16:24:46辰龙
日期:2014-01-08 15:26:12技术图书徽章
日期:2014-01-17 13:24:40巳蛇
日期:2014-02-18 14:32:59未羊
日期:2014-02-20 14:12:13白羊座
日期:2014-02-26 12:06:59
3 [报告]
发表于 2015-09-08 15:30 |只看该作者
回复 1# winsonjie

$ awk '/Msg [^,]+, Level [^,]+, State [^:]+:/{print $0}' FILE
Msg 2812, Level 16, State 5:
Msg 28122, Level 122, State 543:

$ perl -lane '{print if(m/Msg [^,]+, Level [^,]+, State [^:]+:/)}' FILE
Msg 2812, Level 16, State 5:
Msg 28122, Level 122, State 543:

   

评分

参与人数 1信誉积分 +6 收起 理由
汤林 + 6 赞一个!

查看全部评分

论坛徽章:
11
程序设计版块每日发帖之星
日期:2015-09-09 06:20:00CU十四周年纪念徽章
日期:2016-05-16 11:11:112016科比退役纪念章
日期:2016-05-04 17:16:57程序设计版块每日发帖之星
日期:2016-02-20 06:20:00程序设计版块每周发帖之星
日期:2015-11-06 19:30:58程序设计版块每日发帖之星
日期:2015-09-12 06:20:00程序设计版块每日发帖之星
日期:2015-09-11 06:20:00每日论坛发贴之星
日期:2015-09-10 06:20:00程序设计版块每日发帖之星
日期:2015-09-10 06:20:00每日论坛发贴之星
日期:2015-09-09 06:20:0015-16赛季CBA联赛之四川
日期:2016-12-15 15:52:10
4 [报告]
发表于 2015-09-10 16:40 |只看该作者
sed -n /^Msg.*Level.*State.*:/p test.txt
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP