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.

  • 相关阅读:
    Windows server 2008 R2远程桌面终端连接数的破解
    VirtualBox是什么
    蓝屏代码和解决办法
    最新版都叫兽数据恢复软件和注册机
    两种颜色混合
    [译]GLUT教程
    OpenGl的glMatrixMode()函数理解
    OpenGL ES 画直线代码实例
    7天学习opengl入门
    error C2275 将此类型用作表达式非法
  • 原文地址:https://www.cnblogs.com/lake-of-embedded-system/p/3274614.html
Copyright © 2011-2022 走看看