simple (g)awk code
    Ben Horner-Johnson 
    ben at earth.nwu.edu
       
    Wed Jul 21 18:03:58 EDT 1999
    
    
  
> From: Agustin Lobo <alobo at ija.csic.es>
> Subject: simple (g)awk code
> Is there anybody "fluent" in awk (or gawk)
> who could help me with a simple script?
> 
> I just need to read the output of 3
> files produced by r.stat, so like:
> 
> 1 val1a val2a val3a
> 2 val1a val2a val3a
> 3 val1a val2a val3a
> ...
> 
> ("a" indicates that the values are the ones 
> from the first file)
> 
> and then make one single file in the form:
> 
> 1 val1a val2a val1b val2b val1c val2c val3
> 2 val1a val2a val1b val2b val1c val2c val3
> 3 val1a vala2 val1b valb2 val1c val2c val3
> ...
Sure.  With the "paste" command and "(g)awk".
paste puts the columns of each file together on one line:
1 val1a val2a val3a 1 val1b val2b val3b 1 val1c val2c val3c
2 val1a val2a val3a 2 val1b val2b val3b 2 val1c val2c val3c
...
column guide
1   2     3     4   5   6     7     8   9   10    11    12
Use gawk to get the columns you want:
paste file_a file_b file_c | awk '{print $1,$2,$3,$6,$7,$10,$11,$4}' > file_abc
I don't know which val3 you wanted, but the procedure is pretty straightforward.
If the column separators are the same in the files (i.e. tabs) as between the
files (paste defaults to a tab), the utility "cut" can also be used.
paste file_a file_b file_c | cut -f 1,2,3,6,7,10,11,4 > file_abc
Ben Horner-Johnson
ben at earth.nwu.edu
    
    
More information about the grass-user
mailing list