Awk print matched column if exists else print not found

后端 未结 3 1945
终归单人心
终归单人心 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:12

    Whenever you have name=value pairs in your input it's best to first create an array of those mappings (f[] below) and then you can just print (or do anything else with) the values by name:

    $ awk -v n="inbound" -F'[ =]+' '{delete f; for (i=1;i

    Want to do the same for "outbound" or any other field? Just init the name variable n accordingly"

    $ awk -v n="outbound" -F'[ =]+' '{delete f; for (i=1;i

提交回复
热议问题