[CentOS] Semi-OT: awk

Fri Apr 29 17:14:01 UTC 2016
Jon LaBadie <jcu at labadie.us>

On Fri, Apr 29, 2016 at 10:31:51AM -0400, m.roth at 5-cent.us wrote:
> This is odd, and annoying. CentOS 6, current. Here's my awk script:
> 
> {
>    room = substr($0, 48, 10);
>    arr[$2,room,$1] = $0;
> }
> END {
>   for ( i in arr ) {
>      for ( j in arr[i] ) {
>         for ( k in arr[i][j] ) {
>             print arr[i][j][k];
>         }
>      }
>    }
> }
> 

Note the last sentence in this paragraph from the gawk manpage:

   The in construct may also be used in a for loop to iterate over
   all the elements of an array.  However, the (i, j) in array
   construct only works in tests, not in for loops.

jl
-- 
Jon H. LaBadie                 jon at jgcomp.com
 11226 South Shore Rd.          (703) 787-0688 (H)
 Reston, VA  20190              (703) 935-6720 (C)