Find the answer to your Linux question:
Results 1 to 2 of 2
Still trying to get familiar with awk. How does awk deal with elements in columns from different rows? Given: AA ZKYYG BB QRTBG CC TRFDG DD LHSDF how can I ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Feb 2013
    Posts
    37

    Awk (III)


    Still trying to get familiar with awk.

    How does awk deal with elements in columns from different rows?
    Given:

    AA ZKYYG
    BB QRTBG
    CC TRFDG
    DD LHSDF

    how can I ask awk to print "OK" when column 1 in row i matches BB and column 2 in line i+2 matches LH

    Sadly, all I can think of is this, but obviously is not sufficient for this purpose

    awk '{if ( $1 ~ /AA/ && $2 /LH/ print "OK"}'

  2. #2
    Linux Newbie
    Join Date
    Nov 2012
    Posts
    224
    hi,

    use an array in which you'll record from the moment line matches BB until line matches LH
    the print array[NR - 2], and reset array and its index

    EDIT: again, it's not exactly what you're asking for, but it's the way you shold think.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •