Awk - print next record following matched record

前端 未结 2 797
旧时难觅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:17

    No need for slowing things down using a loop :)

    awk -F1 '/FIELDB2/ {f=NR} f&&NR-1==f' RS="1" file
    VALUEB2
    
    0 讨论(0)
  • 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) }' 
    
    0 讨论(0)
提交回复
热议问题