免费注册 查看新帖 |

Chinaunix

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

请教一个复杂的sed的意思 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2010-07-28 12:04 |只看该作者 |倒序浏览
我在使用一个取was的大对象的脚本的时候,内容如下:

find /install/IBM/WebSphere/AppServer/profiles/estore/logs/server1 -name "native_stderr.log" 2>/dev/null|grep -v nodeagent|while read FILE
do
    cat -n $FILE|sed -n -e "/Jul 2[6-8].*2010/{
        =;n;n;n;n;n;n;
        /Allocation request for/{n;p;}
        n;
        /Allocation request for/{n;p;}
        }" |sed -n -e '/at /{x;1!p;g;p;}' -e h |sed '$!N;s/\n/ /' |awk '{print "'$FILE' "$0}'
done |sort +3|uniq -f 3 -c |while read NUM FILES ROWID1 ROWID2 KEYWORD
do
  echo $FILES |sed 's/^\(.*\)\/server1\/native_stderr.log/\2/'|read HOSTNAME
  echo "\n抽样文件: $FILES\n共出现次数: $NUM"
  cat $FILES |sed -n "${ROWID1},/^$/p"
done



这个脚本必须要用ksh执行的,用bash的话会认为脚本没有结束。


请问一下,能不能介绍下这个脚本是怎么处理文本的呢?过程作了什么操作呢?
它输出的结果类似如下的:
抽样文件: /install/IBM/WebSphere/AppServer/profiles/estore/logs/server1/native_stderr.log
共出现次数: 1
  <GC(7891): GC cycle started Tue Jul 27 12:28:00 2010
  <GC(7891): freed 100765928 bytes, 14% free (233579520/1610611200), in 15841 ms>
  <GC(7891): mark: 496 ms, sweep: 45 ms, compact: 15300 ms>
  <GC(7891): refs: soft 3 (age >= 32), weak 21, final 52, phantom 52>
  <GC(7891): moved 14320015 objects, 685845944 bytes, reason=1, used 3640 more bytes>
<AF[4009]: completed in 15843 ms>
Allocation request for 8388624 bytes
        at org.extremecomponents.table.filter.ExportFilter.doFilterInternal(ExportFilter.java:4
        at org.extremecomponents.table.filter.AbstractExportFilter.doFilter(AbstractExportFilter.java(Compiled Code))
        at com.ibm.ws.webcontainer.filter.FilterInstanceWrapper.doFilter(FilterInstanceWrapper.java(Compiled Code))
        at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java(Compiled Code))
        at com.ibm.ws.webcontainer.filter.WebAppFilterChain._doFilter(WebAppFilterChain.java(Compiled Code))
        at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java(Compiled Code))
        at com.ibm.ws.webcontainer.webapp.WebApp.handleRequest(WebApp.java(Compiled Code))
        at com.ibm.ws.webcontainer.webapp.WebGroup.handleRequest(WebGroup.java(Compiled Code))
        at com.ibm.ws.webcontainer.VirtualHost.handleRequest(VirtualHost.java(Compiled Code))
        at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java(Compiled Code))
        at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java(Compiled Code))
        at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java(Compiled Code))
        at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewInformation(HttpInboundLink.java(Compiled Code))
        at com.ibm.ws.http.channel.inbound.impl.HttpICLReadCallback.complete(HttpICLReadCallback.java(Compiled Code))
        at com.ibm.ws.tcp.channel.impl.WorkQueueManager.requestComplete(WorkQueueManager.java(Compiled Code))
        at com.ibm.ws.tcp.channel.impl.WorkQueueManager.attemptIO(WorkQueueManager.java(Compiled Code))
        at com.ibm.ws.tcp.channel.impl.WorkQueueManager.workerRun(WorkQueueManager.java(Compiled Code))
        at com.ibm.ws.tcp.channel.impl.WorkQueueManager$Worker.run(WorkQueueManager.java(Compiled Code))
        at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java(Compiled Code))
Allocation request for 16777232 bytes
        at org.extremecomponents.table.filter.ExportFilter.doFilterInternal(ExportFilter.java:4
        at org.extremecomponents.table.filter.AbstractExportFilter.doFilter(AbstractExportFilter.java(Compiled Code))
        at com.ibm.ws.webcontainer.filter.FilterInstanceWrapper.doFilter(FilterInstanceWrapper.java(Compiled Code))
        at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java(Compiled Code))
        at com.ibm.ws.webcontainer.filter.WebAppFilterChain._doFilter(WebAppFilterChain.java(Compiled Code))
        at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java(Compiled Code))
        at com.ibm.ws.webcontainer.webapp.WebApp.handleRequest(WebApp.java(Compiled Code))
        at com.ibm.ws.webcontainer.webapp.WebGroup.handleRequest(WebGroup.java(Compiled Code))
        at com.ibm.ws.webcontainer.VirtualHost.handleRequest(VirtualHost.java(Compiled Code))
        at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java(Compiled Code))
        at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java(Compiled Code))
        at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java(Compiled Code))
        at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewInformation(HttpInboundLink.java(Compiled Code))
        at com.ibm.ws.http.channel.inbound.impl.HttpICLReadCallback.complete(HttpICLReadCallback.java(Compiled Code))
        at com.ibm.ws.tcp.channel.impl.WorkQueueManager.requestComplete(WorkQueueManager.java(Compiled Code))
        at com.ibm.ws.tcp.channel.impl.WorkQueueManager.attemptIO(WorkQueueManager.java(Compiled Code))
        at com.ibm.ws.tcp.channel.impl.WorkQueueManager.workerRun(WorkQueueManager.java(Compiled Code))
        at com.ibm.ws.tcp.channel.impl.WorkQueueManager$Worker.run(WorkQueueManager.java(Compiled Code))
        at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java(Compiled Code))




另外想请问一下,我在linux下执行这个脚本的时候,用ksh,会报出
sed:-e 表达式 #1,字符 41:invalid reference \2 on `s' command's RHS

请问是不是版本的问题呢?
sed --version
GNU sed version 4.1.4
Copyright (C) 2003 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE,
to the extent permitted by law.


恳请各位指点一下我这两个问题,谢谢。

论坛徽章:
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
2 [报告]
发表于 2010-07-28 12:23 |只看该作者
哪个环境可以正确执行?Solaris?AIX?

论坛徽章:
16
IT运维版块每日发帖之星
日期:2015-08-24 06:20:00综合交流区版块每日发帖之星
日期:2015-10-14 06:20:00IT运维版块每日发帖之星
日期:2015-10-25 06:20:00IT运维版块每日发帖之星
日期:2015-11-06 06:20:00IT运维版块每日发帖之星
日期:2015-12-10 06:20:00平安夜徽章
日期:2015-12-26 00:06:302016猴年福章徽章
日期:2016-02-18 15:30:34IT运维版块每日发帖之星
日期:2016-04-15 06:20:00IT运维版块每日发帖之星
日期:2016-05-21 06:20:00综合交流区版块每日发帖之星
日期:2016-08-16 06:20:002015七夕节徽章
日期:2015-08-21 11:06:17IT运维版块每日发帖之星
日期:2015-08-14 06:20:00
3 [报告]
发表于 2010-07-28 12:33 |只看该作者
写的真够复杂的。光n就用了N个,看的眼花都

论坛徽章:
5
2015年辞旧岁徽章
日期:2015-03-03 16:54:152015年迎新春徽章
日期:2015-03-04 09:50:282015年亚洲杯之朝鲜
日期:2015-03-13 22:47:33IT运维版块每日发帖之星
日期:2016-01-09 06:20:00IT运维版块每周发帖之星
日期:2016-03-07 16:27:44
4 [报告]
发表于 2010-07-28 12:45 |只看该作者
语法出错了。RHS

论坛徽章:
0
5 [报告]
发表于 2010-07-28 12:46 |只看该作者
回复 1# keymanlu


    你能说下你想输出什么吗?

论坛徽章:
0
6 [报告]
发表于 2010-07-28 12:55 |只看该作者
回复 2# Shell_HAT


    是aix下可以输出的

论坛徽章:
0
7 [报告]
发表于 2010-07-28 12:57 |只看该作者
回复  keymanlu


    你能说下你想输出什么吗?
iori809 发表于 2010-07-28 12:46



   

它输出的结果类似如下的:
抽样文件: /install/IBM/WebSphere/AppServer/profiles/estore/logs/server1/native_stderr.log
共出现次数: 1
  <GC(7891): GC cycle started Tue Jul 27 12:28:00 2010
  <GC(7891): freed 100765928 bytes, 14% free (233579520/1610611200), in 15841 ms>
  <GC(7891): mark: 496 ms, sweep: 45 ms, compact: 15300 ms>
  <GC(7891): refs: soft 3 (age >= 32), weak 21, final 52, phantom 52>
  <GC(7891): moved 14320015 objects, 685845944 bytes, reason=1, used 3640 more bytes>
<AF[4009]: completed in 15843 ms>
Allocation request for 8388624 bytes
        at org.extremecomponents.table.filter.ExportFilter.doFilterInternal(ExportFilter.java:4
        at org.extremecomponents.table.filter.AbstractExportFilter.doFilter(AbstractExportFilter.java(Compiled Code))
        at com.ibm.ws.webcontainer.filter.FilterInstanceWrapper.doFilter(FilterInstanceWrapper.java(Compiled Code))
        at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java(Compiled Code))
        at com.ibm.ws.webcontainer.filter.WebAppFilterChain._doFilter(WebAppFilterChain.java(Compiled Code))
        at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java(Compiled Code))
        at com.ibm.ws.webcontainer.webapp.WebApp.handleRequest(WebApp.java(Compiled Code))
        at com.ibm.ws.webcontainer.webapp.WebGroup.handleRequest(WebGroup.java(Compiled Code))
        at com.ibm.ws.webcontainer.VirtualHost.handleRequest(VirtualHost.java(Compiled Code))
        at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java(Compiled Code))
        at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java(Compiled Code))
        at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java(Compiled Code))
        at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewInformation(HttpInboundLink.java(Compiled Code))
        at com.ibm.ws.http.channel.inbound.impl.HttpICLReadCallback.complete(HttpICLReadCallback.java(Compiled Code))
        at com.ibm.ws.tcp.channel.impl.WorkQueueManager.requestComplete(WorkQueueManager.java(Compiled Code))
        at com.ibm.ws.tcp.channel.impl.WorkQueueManager.attemptIO(WorkQueueManager.java(Compiled Code))
        at com.ibm.ws.tcp.channel.impl.WorkQueueManager.workerRun(WorkQueueManager.java(Compiled Code))
        at com.ibm.ws.tcp.channel.impl.WorkQueueManager$Worker.run(WorkQueueManager.java(Compiled Code))
        at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java(Compiled Code))
Allocation request for 16777232 bytes
        at org.extremecomponents.table.filter.ExportFilter.doFilterInternal(ExportFilter.java:4
        at org.extremecomponents.table.filter.AbstractExportFilter.doFilter(AbstractExportFilter.java(Compiled Code))
        at com.ibm.ws.webcontainer.filter.FilterInstanceWrapper.doFilter(FilterInstanceWrapper.java(Compiled Code))
        at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java(Compiled Code))
        at com.ibm.ws.webcontainer.filter.WebAppFilterChain._doFilter(WebAppFilterChain.java(Compiled Code))
        at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java(Compiled Code))
        at com.ibm.ws.webcontainer.webapp.WebApp.handleRequest(WebApp.java(Compiled Code))
        at com.ibm.ws.webcontainer.webapp.WebGroup.handleRequest(WebGroup.java(Compiled Code))
        at com.ibm.ws.webcontainer.VirtualHost.handleRequest(VirtualHost.java(Compiled Code))
        at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java(Compiled Code))
        at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java(Compiled Code))
        at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java(Compiled Code))
        at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewInformation(HttpInboundLink.java(Compiled Code))
        at com.ibm.ws.http.channel.inbound.impl.HttpICLReadCallback.complete(HttpICLReadCallback.java(Compiled Code))
        at com.ibm.ws.tcp.channel.impl.WorkQueueManager.requestComplete(WorkQueueManager.java(Compiled Code))
        at com.ibm.ws.tcp.channel.impl.WorkQueueManager.attemptIO(WorkQueueManager.java(Compiled Code))
        at com.ibm.ws.tcp.channel.impl.WorkQueueManager.workerRun(WorkQueueManager.java(Compiled Code))
        at com.ibm.ws.tcp.channel.impl.WorkQueueManager$Worker.run(WorkQueueManager.java(Compiled Code))
        at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java(Compiled Code))

论坛徽章:
0
8 [报告]
发表于 2010-07-28 12:58 |只看该作者
语法出错了。RHS
blackold 发表于 2010-07-28 12:45



    请问一下,请问是什么地方的问题呢,是不是linux下的sed和aix的sed的语法不一样的原因?

论坛徽章:
0
9 [报告]
发表于 2010-07-28 13:10 |只看该作者
其实我就是很难看懂sed里面的那部分缩写的命令,我对着手册一个个看都很难有合理的逻辑解释这个脚本在做什么,呵呵。

但实际的确是能够取出如上面这样的大对象结果来

论坛徽章:
0
10 [报告]
发表于 2010-07-28 13:30 |只看该作者
回复 7# keymanlu


    这是原文件还是最终输出?
源文件呢?
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP