Operating System - HP-UX
1833747 Members
2672 Online
110063 Solutions
New Discussion

script for inserting form feeds into file

 
james gould
Frequent Advisor

script for inserting form feeds into file

 
3 REPLIES 3
Mark Greene_1
Honored Contributor

Re: script for inserting form feeds into file

if you have a c compiler on your system, you can use this in a pipeline:

/*
* Copy stdin to stdout, insert formfeed every 66 lines.
*/

#include

main() {
int line = 0;
int c;

if ( (c = getchar()) == EOF)
return;

for (;;) {
if (c == '\n')
line++;
putchar(c);

/*
* An odd place to leave the loop, but it keeps a final
* formfeed from being generated when the last page
* has exactly 66 lines.
*/
if ( (c = getchar()) == EOF)
break;

if (line >= 66) {
putchar('\f');
line = 0;
}
}
}


HTH
mark
the future will be a lot like now, only later
Frank Gilsdorf
Advisor

Re: script for inserting form feeds into file

Hi,

I would choose a perl-version:

#!/usr/bin/perl
while ()
{
chop $_;
print "$_\r\n";
}

It should be faster then C because of the very fast string-routines in perl.

Frank
Darrell Allen
Honored Contributor

Re: script for inserting form feeds into file

Same question is in thread:
http://forums.itrc.hp.com/cm/QuestionAnswer/1,,0xadd528e43106d6118ff40090279cd0f9,00.html

If you prefer a script, there's an answer there.

Darrell
"What, Me Worry?" - Alfred E. Neuman (Mad Magazine)