zoukankan      html  css  js  c++  java
  • sed例子

    以care.log这个log文件为例,
    care.log:

    05:44:31,816 DEBUG RawAggregationWorker:70 - LTS is working on Raw Data Aggregation execute Start, Now:1535003071816, currentTimeMillis:1535003071816
    05:44:31,816 DEBUG RawAggregationWorker:57 - LTS is working on Raw Data Aggregation to dataPoints:22, careConfig.getLtsRawaggregationDataPoints():10
    05:46:53,264 DEBUG RawAggregationWorker:100 - LTS is working on Raw Data Aggregation execute End, Now:1535003071816, currentTimeMillis:1535003213264, now Done Took: 141448ms, currentTime Done Took: 141448ms
    05:46:53,265 DEBUG MinAggregationWorker:59 - LTS is working on Min Data Aggregation execute Start, Now:1535002591816, currentTimeMillis:1535003213265
    05:55:04,112 DEBUG MinAggregationWorker:108 - LTS is working on Min Data Aggregation execute End, Now:1535002591816, currentTimeMillis:1535003704112, now Done Took: 1112seconds, currentTime Done Took: 490seconds
    
    05:55:04,112 DEBUG HourAgingWorker:53 - LTS is working on Hourly Aging, now: 1535003011816, currentTimeMillis:1535003704112
    05:58:29,697 DEBUG HourAgingWorker:69 - LTS is working on Hourly Aging, now Done Took: 897881ms, currentTime Done Took: 205585ms
    

    希望结果为:

    Raw Data Aggregation Start-Now:1535003071816;currentTimeMillis:1535003071816;Raw Data Aggregation-dataPoints:10
    Raw Data Aggregation End-Now:1535003071816;currentTimeMillis:1535003213264
    Min Data Aggregation Start-Now:1535002591816;currentTimeMillis:1535003213265
    Min Data Aggregation End-Now:1535002591816;currentTimeMillis:1535003704112
    Hourly Aging-now: 1535003011816;currentTimeMillis:1535003704112
    Hourly Aging-now Done Took: 897881ms;currentTime Done Took: 205585ms
    
    • 匹配从行首到关键字并替换
    sed 's#^.* on ##g'
    
    • 匹配关键字并保留匹配到关键字其中一部分(用括号指代要保留的部分在#后用12.....表示)
    sed 's#(^.*) execute (.*),.*(Now:[0-9]{13}), (currentTimeMillis:[0-9]{13}).*$#1 2-3;4#g'
    
    • 合并匹配到的行与上一行
    sed '{N;s/(.*)
    (^.*dataPoints.*$)/1;2/;t merge;P;D};:merge;p;d' 
    
    • 删除空行
    sed '/^$/d'
    

    awk NF
    
    • 最后,合并在一起:
     cat care.log | sed 's#^.* on ##g' | sed 's#(^.*) execute (.*),.*(Now:[0-9]{13}), (currentTimeMillis:[0-9]{13}).*$#1 2-3;4#g' | sed 's#^(.*) to (dataPoints).*DataPoints():([0-10]{1,})$#1-2:3#g' | sed 's#(^.*), (now.*), (current.*:.*)$#1-2;3#g' | sed '{N;s/(.*)
    (^.*dataPoints.*$)/1;2/;t merge;P;D};:merge;p;d' |awk NF
    
  • 相关阅读:
    putty的复制 技巧
    linux下的yum命令详解
    mysql修改密码
    我的阅读编程书籍的好方法
    WINDOWS下VIM配置
    Debian下VSFTPD配置
    一个远程访问MySQL的错误(2003, 10061)的解决
    auto_increment
    hello,world!
    scss文件中使用深度选择器/deep/报错 Expected selector Jim
  • 原文地址:https://www.cnblogs.com/ocean1100/p/9552310.html
Copyright © 2011-2022 走看看