错误定位命令 grep 关键件 sed 打印对应的行号

6 篇文章 0 订阅

grep 打印出行号


[dongfucai@csc-pacific-task-service01.beta csc-pacific-task-service]$ grep -rin 董付财_20180607115557.xlsx service.log 

1772963:2018-06-07 12:02:43.419 - - [INFO] pool-20-thread-1 MafkaLogger #XMDT#{__traceId__=7978079490297630283}#XMDT# (CaseExportListener.java:145) 新工单导出异步消息队列, type[ CONSUME ], topic[ csc-pacific-case-export ], message[ {"id":1680,"creatorId":618,"status":0,"fileAddress":null,"createTime":1528343757925,"updateTime":1528343757925,"searchInput":"{\"defaultFields\":{\"business\":[12],\"orderType\":[],\"questionType\":[],\"question\":[],\"caseType\":[],\"caseStatus\":[],\"processor\":[],\"fourthCategoryId\":[],\"fifthCategoryId\":[]},\"baseFields\":[],\"statisticFields\":[],\"extendFields\":[],\"dataObjectFields\":[],\"scrollId\":null,\"sortField\":\"updateTime\",\"sortOrder\":\"desc\",\"export\":false,\"filtered\":false}","fileName":"董付财_20180607115557.xlsx"} ]

1772964:2018-06-07 12:02:43.419 - - [INFO] pool-20-thread-1 CaseExportListener #XMDT#{__traceId__=7978079490297630283}#XMDT# (CaseExportListener.java:148) [工单导出消息监听 ]  接受消息 body = {"id":1680,"creatorId":618,"status":0,"fileAddress":null,"createTime":1528343757925,"updateTime":1528343757925,"searchInput":"{\"defaultFields\":{\"business\":[12],\"orderType\":[],\"questionType\":[],\"question\":[],\"caseType\":[],\"caseStatus\":[],\"processor\":[],\"fourthCategoryId\":[],\"fifthCategoryId\":[]},\"baseFields\":[],\"statisticFields\":[],\"extendFields\":[],\"dataObjectFields\":[],\"scrollId\":null,\"sortField\":\"updateTime\",\"sortOrder\":\"desc\",\"export\":false,\"filtered\":false}","fileName":"董付财_20180607115557.xlsx"}

1796702:2018-06-07 12:03:27.409 - - [ERROR] pool-20-thread-1 CaseExportListener #XMDT#{__traceId__=7978079490297630283}#XMDT# (CaseExportListener.java:163) [工单导出消息监听 ]  接受预约、超时事件消息异常 mafkaMessage = [MafkaMessage{topic='csc-pacific-case-export', parttion=1, offset=774, msgKey=null, body={"id":1680,"creatorId":618,"status":0,"fileAddress":null,"createTime":1528343757925,"updateTime":1528343757925,"searchInput":"{\"defaultFields\":{\"business\":[12],\"orderType\":[],\"questionType\":[],\"question\":[],\"caseType\":[],\"caseStatus\":[],\"processor\":[],\"fourthCategoryId\":[],\"fifthCategoryId\":[]},\"baseFields\":[],\"statisticFields\":[],\"extendFields\":[],\"dataObjectFields\":[],\"scrollId\":null,\"sortField\":\"updateTime\",\"sortOrder\":\"desc\",\"export\":false,\"filtered\":false}","fileName":"董付财_20180607115557.xlsx"}, timestamp=1528343757999, messageID='54fa4fc7-e095-412a-805a-df9d7537d502', clusterName='yf-mafka2-common'}],错误内容:分页查询与分页写入出错:工单查询未成功,或者数据为空




找到某行错误后 可以进行head -n 和tail -n 进行定位



或者 sed -n 行号进行打印定位




cat test.txt

123
234
345
542
adb
lsnd


我想打印每个文件除了最后两行的数据,脚本如下:


#!/bin/sh

line1=`wc -l test.txt`
line2=`expr $line1 - 2`

sed -n '1,$line2p' test.txt 

因为test.txt大小会变,想通过一个变量实现,在sed 显示行号中无法使用变量
好像$line2p看成了一个变量了...

——————————————————————————————————————

解答:

sed -n '1,'$line2'p' test.txt

sed -n 1,${line2}p  test.txt



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值