Awk print matched column if exists else print not found

后端 未结 3 1944
终归单人心
终归单人心 2021-01-24 03:47

My text file looks like below

date=\"2017-10-10\" ip=192.168.1.1:22 inbound=100 outbound=100
date=\"2017-10-10\" ip=192.168.1.1:22 inbound=100
date=\"2017-10-10         


        
3条回答
  •  执笔经年
    2021-01-24 04:11

    Using GNU awk

    awk '{print match($0,/inbound=([0-9]+)/,a)?a[1]:0}' file
    

    In perl

    perl -lne 'print /inbound=(\d+)/?$1:0' file
    

    In sed

    sed 's/.*inbound=\([0-9]\+\).*/\1/;t;s/.*/0/' file
    

提交回复
热议问题