免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1623 | 回复: 2

[文本处理] awk 引用shell变量问题 [复制链接]

论坛徽章:
0
发表于 2013-03-07 21:31 |显示全部楼层
cat file  
TotalLoad      =96325      MinuteLoad     =14          MsgDiscarded   =0         
  UsrMsgDiscarded=0          SessionCount   =1           MaxSessionCount=1         
  TimerCount     =3          MaxTimerCount  =4           SessionThreadIndex=0         

0304 23:24:54.508 10305 OMAgent-8 Service statistics : ServiceName=NamingAgent
  ModuleID       =11         ThreadCount    =1           ThreadIndex    =3         
  TotalLoad      =6          MinuteLoad     =0           MsgDiscarded   =0         
  UsrMsgDiscarded=0          SessionCount   =0           MaxSessionCount=0         
  TimerCount     =0          MaxTimerCount  =0           SessionThreadIndex=0         

0305 23:24:54.508 192631 OMAgent-8 Service statistics : ServiceName=LoadBalance
  ModuleID       =12         ThreadCount    =1           ThreadIndex    =9         
  TotalLoad      =144479     MinuteLoad     =21          MsgDiscarded   =0         
  UsrMsgDiscarded=0          SessionCount   =0           MaxSessionCount=0         
  TimerCount     =2          MaxTimerCount  =2           SessionThreadIndex=0     

tdate="0305"

awk如何匹配shell变量为tdate0305开头的行,
即只匹配0305 23:24:54.508 192631 OMAgent-8 Service statistics : ServiceName=LoadBalance
而不匹配0304 23:24:54.508 10305 OMAgent-8 Service statistics : ServiceName=NamingAgent

awk -v date=$tdate '{if( $0 ~ date) print}' file

论坛徽章:
0
发表于 2013-03-07 21:47 |显示全部楼层
已解决.

论坛徽章:
33
ChinaUnix元老
日期:2015-02-02 08:55:39CU十四周年纪念徽章
日期:2019-08-20 08:30:3720周年集字徽章-周	
日期:2020-10-28 14:13:3020周年集字徽章-20	
日期:2020-10-28 14:04:3019周年集字徽章-CU
日期:2019-09-08 23:26:2519周年集字徽章-19
日期:2019-08-27 13:31:262016科比退役纪念章
日期:2022-04-24 14:33:24
发表于 2013-03-07 22:13 |显示全部楼层
2013-03-07 21:31:59
2013-03-07 21:47:23
冲动是魔鬼啊
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP