zoukankan      html  css  js  c++  java
  • use AWK to extract some lines according to some patterns in file

    A file named  Demo.txt, is like this:

    @@@0x5100002c is 0 @@@
    0x51000018 is 101111
    0x5100001c is e000e
    0x51000020 is 121111
    0x51000024 is f000f
    0x51000024 is f000f
    0x51000028 is 0
    0x51000030=0x00000606
    0x51000034=0x00445221
    0x51000038=0x02003faa
    
    dly90_para_lock=0xf000f
    max_begin is 0
    max_end is 23
    max_one is 24
    dqs_window is 11
    
     r0= 0 , r1 = 1, r2 = 1, r3 = 1, r4 = 1, r5 = 0
    
    SDRDDR_DQSWIN is 22
    SDRDDR_MODE is 100
    DDR Success 1
    DDR Success 2
    DDR Success 3
    DDR Success 4
    @@@0x5100002c is 26260006 @@@
    After ddr_init!
    0x51000018=0x00101111
    0x5100001c=0x000e000e
    0x51000020=0x00121111
    0x51000024=0x000f000f
    0x51000028 =0x00000000
    0x51000030=0x00000606
    0x51000034=0x00445221
    0x51000038=0x02003faa
    

    Now, I want to extract lines

    dly90_para_lock=0xf000f
    max_begin is 0
    max_end is 23
    

     and the line heading with "@@@0x5100002c"

    So, I use

    [shawn@test]$ cat Demo.txt | awk ' $1 ~ /dly90_para_lock/, $1=="max_end"; $1=="@@@0x5100002c" {print $0} '

    The result is as follows:

    dly90_para_lock=0x100010
    max_begin is 0
    max_end is 24
    @@@0x5100002c is 27270006 @@@
    @@@0x5100002c is 0 @@@
    dly90_para_lock=0xf000f
    max_begin is 0
    max_end is 23
    @@@0x5100002c is 26260006 @@@
    @@@0x5100002c is 0 @@@
    dly90_para_lock=0xf000f
    max_begin is 0
    max_end is 22
    @@@0x5100002c is 27270006 @@@
    @@@0x5100002c is 0 @@@
    dly90_para_lock=0xf000f
    max_begin is 0
    max_end is 22
    @@@0x5100002c is 27270006 @@@

    Parse:

    in awk ' $1 ~ /dly90_para_lock/, $1=="max_end"; $1=="@@@0x5100002c" {print $0} '

    $1 ~ /dly90_para_lock/, $1=="max_end" is a pattern, it means,

    begin from the line which contains substring "dly90_para_lock", and end at the line containing substring "max_end"

    the ';'  is a delimeter for another pattern,

     $1=="@@@0x5100002c" is another pattern, it means,

    if the first column in a line is the string "@@@0x5100002c",

    And the action for both patterns is print the whole line. indicated by  $0

    The two patterns ensure the file is dealt with in order,  so the output is in order.

    cat Demo.txt | awk ' sub(/^dly90_para_lock=/ , "") && sub(/....$/, "") ; $1=="max_begin", $1=="max_end" {print $3}'

    That's all this time.

  • 相关阅读:
    Hibernate使用固定值关联表
    使用spring-data-JPA调用存储过程
    angularjs动态添加节点时,绑定到$scope中
    JPA子查询
    表格表头固定的一种实现方式
    Unicode、UTF8与UTF16
    primefaces4.0基本教程以及增删改查
    tomcat发布webservice
    KonBoot – 只要5K映象文件轻易绕过您的WindowsXP/VISTA/7系统的密码
    Setting .xap MIME Type for Silverlight
  • 原文地址:https://www.cnblogs.com/lake-of-embedded-system/p/3274614.html
Copyright © 2011-2022 走看看