INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

store and isolate bad pages from a file to new file

store and isolate bad pages from a file to new file

store and isolate bad pages from a file to new file

(OP)
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





RE: store and isolate bad pages from a file to new file

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

CODE --> awk

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

Annihilannic
tgmlify - code syntax highlighting for your tek-tips posts

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close