• 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.

  • 相关阅读:
    第 9 章 完成购物车
    新建 ASP.NET MVC 项目快速代码
    一个真正的应用程序(第7~8章)(所需代码在下一篇随笔里)
    HTML
    squid 高匿设置
    Linux操作系统上ADSL拨号上网的方法详解
    MYSQL-max_binlog_cache_size参数
    mysql查杀会话
    centos配置Tomcat以指定的身份(非root)运行
    mysql load data导入脚本
  • 原文地址:https://www.cnblogs.com/lake-of-embedded-system/p/3274614.html
Copyright © 2020-2023  润新知