letitbesqzr
V2EX  ›  问与答

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

  •  
  •   letitbesqzr · Aug 7, 2014 · 3851 views
    This topic created in 4476 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
    hcy
    Aug 7, 2014
    1
    awk '$1 ~ /regx/ {print $1 ,$2}' test
    msg7086
    msg7086
    Aug 7, 2014
    2
    说个跑题的。这可以用grep吧。
    hcy
    hcy
    Aug 7, 2014
    3
    可以直接grep .......
    rrfeng
    rrfeng
    Aug 7, 2014
    4
    awk ’/[1-9][0-9]{4,12}/‘

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