To add a pagebreak to the text file

pvsbandi used Ask the Experts™

I have a text file (attached).
 I have a requirement to add pagebreaks to a text file.
So, wherever the header with the below text shows up, we need to move it to the next page.

 Please help.
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
ste5anSenior Developer
There is no such thing like a page break in a text file. Whether there is a "page break" or not depends on the output device. The only thing which exists is the form feed ASCII character (FF, 0x0C).

So you need to read you text file line by line. When the line is your header line add the FF in front of it.
Ste5an is correct.  For printers that recognise the epson esc 2p codes the escape sequence for a form feed is per
charcter 12 in decimal, C in hex.
This assumes there's no header on the file when sent to the printer instructing the printer to treat the file as postscript or another page description language.


Would it be possible to give an example code based on the attached text?
The format looks like a VM CMS Spool file from an IBM mainframe or similar, where the first column dictates page breaks etc, with
1 indicating a page break and
0 indicating that the line is longer than the report width, e.g. a 128 column line wrapped to 80 columns.
Your code will need to
Loop through all the lines of text.
Check whether the left most character is a zero character.  If it's not the first page, output a page brake, then the rest of the line.
Optionally, if the first character is 0, append the following line (tricky flow control in your loop).
You are likely already familiar with the left command.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial