Skip to main content
Code formating to show empty lines.
Source Link
user232326
user232326

I'm trying to pre-process an invoice file and separate each invoice into separate files. The invoices may be multi-page. The header of EACH PAGE looks like this (note formatting tool deletes the blank lines):







                                                                 121084
                                                                   A134
                                                               09.17.19
                                                                      1

There are 6 blank lines at the top of each page, followed by the invoice #, customer #, date and page # (then the rest of the invoice).

At each " 1" (70 spaces followed by "1") on line 10 of each page (Line 10 of each page is the invoice's page #), I need to insert some text on line 1 (which will be used as a delimiter to split the file). Invoices can have multiple pages but the " 1" (70 spaces followed by "1") indicates that this is a new invoice.

When " 1" (70 spaces followed by "1") is encountered, I want to insert some text on the blank line that is 9 lines above it (which is the first line of this invoice). Do this for every every occurrence in the file. Then I can break the file apart into a separate file for each invoice.

I know I can use sed to insert data immediately before the pattern but how can I insert data 9 lines above it?

I can usually get it done with sed & awk but this one is stumping me.

Thanks for any assistance.

John Z

I'm trying to pre-process an invoice file and separate each invoice into separate files. The invoices may be multi-page. The header of EACH PAGE looks like this (note formatting tool deletes the blank lines):

                                                             121084
                                                               A134
                                                           09.17.19
                                                                  1

There are 6 blank lines at the top of each page, followed by the invoice #, customer #, date and page # (then the rest of the invoice).

At each " 1" (70 spaces followed by "1") on line 10 of each page (Line 10 of each page is the invoice's page #), I need to insert some text on line 1 (which will be used as a delimiter to split the file). Invoices can have multiple pages but the " 1" (70 spaces followed by "1") indicates that this is a new invoice.

When " 1" (70 spaces followed by "1") is encountered, I want to insert some text on the blank line that is 9 lines above it (which is the first line of this invoice). Do this for every every occurrence in the file. Then I can break the file apart into a separate file for each invoice.

I know I can use sed to insert data immediately before the pattern but how can I insert data 9 lines above it?

I can usually get it done with sed & awk but this one is stumping me.

Thanks for any assistance.

John Z

I'm trying to pre-process an invoice file and separate each invoice into separate files. The invoices may be multi-page. The header of EACH PAGE looks like this:







                                                                 121084
                                                                   A134
                                                               09.17.19
                                                                      1

There are 6 blank lines at the top of each page, followed by the invoice #, customer #, date and page # (then the rest of the invoice).

At each " 1" (70 spaces followed by "1") on line 10 of each page (Line 10 of each page is the invoice's page #), I need to insert some text on line 1 (which will be used as a delimiter to split the file). Invoices can have multiple pages but the " 1" (70 spaces followed by "1") indicates that this is a new invoice.

When " 1" (70 spaces followed by "1") is encountered, I want to insert some text on the blank line that is 9 lines above it (which is the first line of this invoice). Do this for every every occurrence in the file. Then I can break the file apart into a separate file for each invoice.

I know I can use sed to insert data immediately before the pattern but how can I insert data 9 lines above it?

I can usually get it done with sed & awk but this one is stumping me.

added 521 characters in body
Source Link

I'm trying to pre-process an invoice file and separate each invoice into separate files. The invoices may be multi-page. The header of EACH PAGE looks like this (Line #s added for clarity:

1:

2:

3:

4note formatting tool deletes the blank lines):

5:

                                                             121084
                                                               A134
                                                           09.17.19
                                                                  1

There are 6:

7:                121084

8:                A134

9:                09.17 blank lines at the top of each page, followed by the invoice #, customer #, date and page # (then the rest of the invoice).19

10:                1

At each " 1" 1" (70 spaces followed by "1") on line 10 of each page (whichLine 10 of each page is the invoice's page #), I need to insert some text on line 1 (which will be used as a delimiter to split the file). Invoices can have multiple pages but the " 1" (70 spaces followed by "1") indicates that this is a new invoice.

When " 1" (70 spaces followed by "1") is encountered, I want to insert some text on the blank line that is 9 lines above it (which is the first line of this invoice). Do this for every every occurrence in the file. Then I can break the file apart into a separate file for each invoice.

I know I can use sed to insert data immediately before the pattern but how can I insert data 9 lines above it?

I can usually get it done with sed & awk but this one is stumping me.

Thanks for any assistance.

John Z

I'm trying to pre-process an invoice file and separate each invoice into separate files. The invoices may be multi-page. The header looks like this (Line #s added for clarity:

1:

2:

3:

4:

5:

6:

7:                121084

8:                A134

9:                09.17.19

10:                1

At each " 1" on line 10 (which is the page #), I need to insert some text on line 1 (which will be used as a delimiter to split the file).

I know I can use sed to insert data immediately before the pattern but how can I insert data 9 lines above it?

I can usually get it done with sed & awk but this one is stumping me.

Thanks for any assistance.

John Z

I'm trying to pre-process an invoice file and separate each invoice into separate files. The invoices may be multi-page. The header of EACH PAGE looks like this (note formatting tool deletes the blank lines):

                                                             121084
                                                               A134
                                                           09.17.19
                                                                  1

There are 6 blank lines at the top of each page, followed by the invoice #, customer #, date and page # (then the rest of the invoice).

At each " 1" (70 spaces followed by "1") on line 10 of each page (Line 10 of each page is the invoice's page #), I need to insert some text on line 1 (which will be used as a delimiter to split the file). Invoices can have multiple pages but the " 1" (70 spaces followed by "1") indicates that this is a new invoice.

When " 1" (70 spaces followed by "1") is encountered, I want to insert some text on the blank line that is 9 lines above it (which is the first line of this invoice). Do this for every every occurrence in the file. Then I can break the file apart into a separate file for each invoice.

I know I can use sed to insert data immediately before the pattern but how can I insert data 9 lines above it?

I can usually get it done with sed & awk but this one is stumping me.

Thanks for any assistance.

John Z

edited tags
Link
Jeff Schaller
  • 68.8k
  • 35
  • 122
  • 264
Source Link
Loading