Awk - print next record following matched record

前端 未结 2 796
旧时难觅i
旧时难觅i 2021-02-10 22:59

I\'m trying to get a next field after matching field using awk.

Is there an option to do that or do I need to scan the record into array then check each field in array a

2条回答
  •  别那么骄傲
    2021-02-10 23:20

    You can match the line, then loop over the fields for a match, and print the next record:

    awk -F1 '/FIELDB2/ { for (x=1;x<=NF;x++) if ($x~"FIELDB2") print $(x+1) }' 
    

提交回复
热议问题