[GRASS-user] convert r.report output to spreadsheet format

Giovanni Pasini jynxtor at gmail.com
Wed Feb 25 04:39:31 EST 2009


maning sambale wrote:
> Thanks!
> An example of the r.report output:
> |-----------------------------------------------------------------------------|
> |              Category Information               |          |     cell|   %  |
> | #|description                                   |  hectares|    count| cover|
> |-----------------------------------------------------------------------------|
> | 1|Siquijor                                      |    31,313|   385511|  0.05|
> |  |----------------------------------------------|----------|---------|------|
> |  |112|Broadleaf - open canopy. . . . . . . . . .|      8265|   101755| 26.39|
> |  |140|Mangrove . . . . . . . . . . . . . . . . .|       173|     2125|  0.55|
> |  |210|Agriculture-annual . . . . . . . . . . . .|      7370|    90737| 23.54|
> |  |310|Scrub. . . . . . . . . . . . . . . . . . .|      1063|    13081|  3.39|
> |  |320|Grassland. . . . . . . . . . . . . . . . .|      7185|    88460| 22.95|
> |  |400|Built-up . . . . . . . . . . . . . . . . .|       103|     1270|  0.33|
> |  |510|Inland water . . . . . . . . . . . . . . .|        44|      539|  0.14|
> |  |  *|no data. . . . . . . . . . . . . . . . . .|      7111|    87544| 22.71|
> 
> I want converted to:
> Province,land_cover_code,description,hectares,cell_count,percent_cover
> 
> I will try the cryptic awk lines.
> 
> 
> On Wed, Feb 25, 2009 at 12:12 AM, Giovanni Pasini <jynxtor a gmail.com> wrote:
>> maning sambale ha scritto:
>>> Hi,
>>>
>>> Looking for tips in "transforming" r.report output into a
>>> "spreadsheet" like format.
>>>
>> Hi,
>> I use awk (change NF and the other fields $*):
>>
>> r.report -n map=gri_1000_in,dem2_idw_100_slope_rec units=h,p,c | awk 'BEGIN
>> {FS="|";OFS="|"} !/---/ && NF==7 {intest=$2} NF==8 {sub(/[ .]*$/,"",$4);
>> print intest, $4, $6}' > report_slope.txt
>>
>> This from a non awk expert!
>>
>> cheers,
>> giovanni
>> _______________________________________________
>> grass-user mailing list
>> grass-user a lists.osgeo.org
>> http://lists.osgeo.org/mailman/listinfo/grass-user
>>
> 
> 
> 

try this:

cat report.txt |awk 'BEGIN {FS="|";OFS="|"} !/---/ && NF==7 {intest=$3} 
NF==8 {sub(/[ .]*$/,"",$4); print intest, $4,$5,$6,$7}'

or better:

cat report.txt | awk 'BEGIN {FS="|";OFS="|"} !/---/ && NF==7 {intest=$3} 
NF==8 {sub(/[ .]*$/,"",$4); sub(/[ ]*$/,"",intest); printf 
"%s|%s|%d|%d|%.2f\n",intest,$4,$5,$6,$7}'


giovanni




More information about the grass-user mailing list