letitbesqzr
V2EX  ›  问与答

awk 如何让符合正则表达式的行输出

  •  
  •   letitbesqzr · Aug 7, 2014 · 3530 views
    This topic created in 4326 days ago, the information mentioned may be changed or developed.
    数据如下:
    98875455 xxxxx
    asddsds xxxxxx
    778863545 xxxxxx
    123665545 xxxxxx
    xxxx xxxxx

    只输出符合正则 [1-9][0-9]{4,12} 的:
    778863545 xxxxxx
    123665545 xxxxxx
    98875455 xxxxx
    5 replies    2014-10-05 13:42:43 +08:00
    hcy
        1
    hcy  
       Aug 7, 2014
    awk '$1 ~ /regx/ {print $1 ,$2}' test
    msg7086
        2
    msg7086  
       Aug 7, 2014
    说个跑题的。这可以用grep吧。
    hcy
        3
    hcy  
       Aug 7, 2014
    可以直接grep .......
    rrfeng
        4
    rrfeng  
       Aug 7, 2014
    awk ’/[1-9][0-9]{4,12}/‘

    这不是最基本的用法么。。。。
    mystuff
        5
    mystuff  
       Oct 5, 2014
    grep "[1-9]\{8,9\}"
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   4054 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 49ms · UTC 05:20 · PVG 13:20 · LAX 22:20 · JFK 01:20
    ♥ Do have faith in what you're doing.