以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'
  • 匹配关键字并保留匹配到关键字其中一部分(用括号指代要保留的部分在#后用\1\2.....表示)
sed 's#\(^.*\) execute \(.*\),.*\(Now:[0-9]\{13\}\), \(currentTimeMillis:[0-9]\{13\}\).*$#\1 \2-\3;\4#g'
  • 合并匹配到的行与上一行
sed '{N;s/\(.*\)\n\(^.*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/\(.*\)\n\(^.*dataPoints.*$\)/\1;\2/;t merge;P;D};:merge;p;d' |awk NF

sed例子的更多相关文章

  1. sed 例子

    sed 应用示例 给1.1.1.1后面增加2.2.2.2: sed -i 's/Server=1.1.1.1/&,2.2.2.2/g' zabbix_agentd.conf

  2. Linux shell之sed

    sed编辑器逐行处理输入,然后把结果发送到屏幕. -i选项:直接作用源文件,源文件将被修改. sed命令和选项: a\ 在当前行后添加一行或多行 c\ 用新文本替换当前行中的文本 d 删除行 i\ 在 ...

  3. Shell中sed使用

    sed是一种在线编辑器,它一次处理一行内容.处理时,把当前处理的行存储在临时缓冲区中,称为“模式空间”(pattern space),接着用sed命令处理缓冲区中的内容,处理完成后,把缓冲区的内容送往 ...

  4. 正则与sed,grep,awk三剑客

    系统登录顺序: /etc/profile /etc/profile.d/a.sh (a.sh自己建的) /root/.bash_profile /root/.bashrc /etc/bashrc /b ...

  5. shell-sed命令详解(转)

    (转自http://blog.csdn.net/wl_fln/article/details/7281986) Sed简介 sed是一种在线编辑器,它一次处理一行内容.处理时,把当前处理的行存储在临时 ...

  6. 通过几个例子看sed的模式空间与保持空间

    SED之所以能以行为单位的编辑或修改文本,其原因在于它使用了两个空间:一个是活动的“模式空间(pattern space)”,另一个是起辅助作用的“暂存缓冲区(holdingspace)这2个空间的使 ...

  7. [svc]sed&awk过滤行及sed常用例子

    - sed过滤行 sed '2p' sed '2,5p' sed '2p;3p;4p' - awk过滤行 awk 'NR==2' awk 'NR>=2 && NR <=3' ...

  8. awk、sed处理文件的简单例子

    awk.sed对处理日志文件和写shell脚本时非常有益.这个东西,如果不经常操作,真心过一段时间就忘差不多..要掌握熟练,就要多练习,这没什么可说的. awk '条件{命令}' filename 假 ...

  9. linux(centos8):sed命令的应用例子

    一,sed命令的用途 sed是Linux下一款功能强大的非交互流式文本编辑器, 可以对文本文件进行增.删.改.查等操作, 支持按行.按字段.按正则匹配文本内容. 说明:刘宏缔的架构森林是一个专注架构的 ...

随机推荐

  1. mongodb 启动数据库失败原因及解决办法

    刚开始接触mongodb 每次启动完数据库  用好之后退出时直接 command+q强制退出了 导致了下一次数据库启动失败 错误原因: 上一次退出数据库端口号并没有杀死 解决办法 lsof -i tc ...

  2. Python+request 登录接口reponse的返回值token跨py文件的传递《二》

    主要使用场景: 一般我们在进行接口测试时,依赖登录接口后reponse中的某些返回值,因此需要将login接口单独写一个py文件,另外的py文件均可调用login的reponse返回值使用.共用登录接 ...

  3. appium+python 【Mac】UI自动化测试封装框架介绍 <五>---脚本编写(多设备)

    目的: 通过添加设备号,则自动给添加的设备分配端口,启动对应的appium服务.注意:为了方便,将共用一个配置文件. 1.公共的配置文件名称:desired_caps.yaml platformVer ...

  4. Oracle-锁的查询和处理

    1.查出锁定object的session的信息以及被锁定的object名 SELECT L.SESSION_ID SID, S.SERIAL#, L.LOCKED_MODE, L.ORACLE_USE ...

  5. C指针与数组

    通过指针遍历数组的小把戏 #include<stdio.h> #include<stdlib.h> #include<Windows.h> void main() ...

  6. MySQL index使用率查询

    SELECT  t.table_schema AS db,  t.table_name   AS tab_name,  s.index_name   AS index_name,  s.column_ ...

  7. fmt

    fmt.Println("hello world") fmt.Printf("%T",a)打印a 的类型 fmt.Printf("%v",a ...

  8. luogu2034

    /* * 正难则反 * f[i] 表示前 i 个数中被删除的数的最小和 * f[i] = min(f[j]) + num, i - k + 1 <= j < i; * 单调队列维护 */ ...

  9. SPOJ GSS1 - Can you answer these queries I(线段树维护GSS)

    Can you answer these queries I SPOJ - GSS1 You are given a sequence A[1], A[2], -, A[N] . ( |A[i]| ≤ ...

  10. 一图了解DLL和SYS的区别

    The following diagram shows the device node, kernel-mode device stack, and the user-mode device stac ...