For Programmers: Free Programming Magazines  


Home > Archive > AWK > February 2005 > Help In Producing awk Report









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Help In Producing awk Report
Buck Turgidson

2005-02-01, 8:55 pm

I have a ton of report definition files that are like the sample below, and
I need to write an awk to produce the 2nd listing. Because of my limited
abilities, and the fact that I always end up writing awk under pressure once
a year, I am running into problems. Each file contains a report header,
which I want to repeat throughout the report. The value for the token DBCOL
may or may not have double-quotes, and the heading column may be empty or
populated.

Any help with producing this report would be appreciated (it is not
homework, I wish it was).

TITLE "LINE QUALITY CONTROL REPORT"
DBCOL ORDER HEAD ""
DBCOL ALLOWANCE HEAD ""
DBCOL ADJUST HEAD ""
DBCOL "NET ALLOW" HEAD ""
DBCOL ITEMS HEAD ""
DBCOL "LINE NUM" HEAD "LINE#"


LINE QUALITY CONTROL REPORT ORDER
LINE QUALITY CONTROL REPORT ALLOWANCE
LINE QUALITY CONTROL REPORT ADJUST
LINE QUALITY CONTROL REPORT NET ALLOW
LINE QUALITY CONTROL REPORT ITEMS
LINE QUALITY CONTROL REPORT LINE NUM LINE#




Ed Morton

2005-02-02, 3:56 am



Buck Turgidson wrote:

> I have a ton of report definition files that are like the sample below, and
> I need to write an awk to produce the 2nd listing. Because of my limited
> abilities, and the fact that I always end up writing awk under pressure once
> a year, I am running into problems. Each file contains a report header,
> which I want to repeat throughout the report. The value for the token DBCOL
> may or may not have double-quotes, and the heading column may be empty or
> populated.
>
> Any help with producing this report would be appreciated (it is not
> homework, I wish it was).
>
> TITLE "LINE QUALITY CONTROL REPORT"
> DBCOL ORDER HEAD ""
> DBCOL ALLOWANCE HEAD ""
> DBCOL ADJUST HEAD ""
> DBCOL "NET ALLOW" HEAD ""
> DBCOL ITEMS HEAD ""
> DBCOL "LINE NUM" HEAD "LINE#"
>
>
> LINE QUALITY CONTROL REPORT ORDER
> LINE QUALITY CONTROL REPORT ALLOWANCE
> LINE QUALITY CONTROL REPORT ADJUST
> LINE QUALITY CONTROL REPORT NET ALLOW
> LINE QUALITY CONTROL REPORT ITEMS
> LINE QUALITY CONTROL REPORT LINE NUM LINE#


Something like this (untested) should do it:

gawk '/TITLE/{$1="";title=$0);next}
{$1=title;$(NF-1)="";gsub("\"","");print}' file

If your heading column can contain spaces between the quotes, then you
need a slightly different solution. If you care about the spacing,
there's other ways to do the same thing but using gsub/gensub and REs
that wouldn't cause $0 to get reconstructed

Ed.
William James

2005-02-02, 3:56 am

z BEGIN { FS = " +DBCOL \"?|\"? +HEAD \"" }
z
z gsub( /^TITLE "|"$/, "" ) > 1 {
z title = $0
z next
z }
z
z { printf "%s %-15s %s\n", title, $2, $3 }

Buck Turgidson

2005-02-02, 3:55 pm

Thanks. I am slugging my way through this. I love awk. I wish I had an
opportunity to write more of it.


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com