Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

store and isolate bad pages from a file to new file

Status
Not open for further replies.

ehabaziz20012001

Programmer
Jan 13, 2006
10
0
0
EG
I have a file like below . The good pages must have 3 conditions :
The pages that containing page total only must have 50 lines.
The pages that containing customer total only must have 53 lines.
The last page of Customer Total should be the last page.
How can I accomplish separating good pages from bad pages using GAWK ?
File :
-------
FFstarting good page1(50 line) Account number : 12500149
..
..
..
Total of page : 5555
FFstarting good page2(50 line) Account number : 12500149
..
..
..
Total of page : 6666
FFstarting good page3(53 line) Account number : 12500149
..
..
..
Total of page : 6666
Total Customer : 999.99
FFstarting BAD page1(Not 50 line) Account number : 12500148
..
..
..
Total of page : 5555
FFstarting BAD page2(Not 50 line) Account number : 12500148
..
..
..
Total of page : 6666
FFstarting BAD page3(Not 53 line) Account number : 12500148
..
..
..
Total of page : 6666
Total Customer : 999.99





 
Something like this? Not sure what you mean by "The last page of Customer Total should be the last page" though...

Code:
awk '
        [olive]function[/olive] checkpage() {
                [olive]if[/olive] ( (totalcust && lines == 53) || lines == 50 ) {
                        output=[red]"[/red][purple]goodpages[/purple][red]"[/red]
                } [olive]else[/olive] {
                        output=[red]"[/red][purple]badpages[/purple][red]"[/red]
                }
                [olive]for[/olive] (i=1;i<=lines;i++) { [b]print[/b] page[i] >> output }
                lines=totalcust=0
        }
        [green]BEGIN[/green] { lines=totalcust=0 }
        [green]/^FF/[/green] { checkpage() }
        { page[++lines]=[blue]$0[/blue] }
        [green]/^Total Customer/[/green] { totalcust=1 }
        [green]END[/green] { checkpage() }
' inputfile


Annihilannic
[small]tgmlify - code syntax highlighting for your tek-tips posts[/small]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top