letitbesqzr
V2EX  ›  问与答

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

  •  
  •   letitbesqzr · Aug 7, 2014 · 3481 views
    This topic created in 4302 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   ·   1019 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 38ms · UTC 22:35 · PVG 06:35 · LAX 15:35 · JFK 18:35
    ♥ Do have faith in what you're doing.