Coverting newlines into form feed

Coverting newlines into form feed

am 08.04.2008 23:06:48 von sajohn52

I have a text file with no page breaks but each page is broken up by 4
newline character. I'm having trouble converting these newline
character into a form feed. I've tried using

tr "[\n*4]" "\f" < input-file > out_file

but this doesn't work. Can anyone tell me what I'm doing wrong?

Re: Coverting newlines into form feed

am 08.04.2008 23:24:13 von Bill Marcum

On 2008-04-08, sajohn52@gmail.com wrote:
>
>
>
>
> I have a text file with no page breaks but each page is broken up by 4
> newline character. I'm having trouble converting these newline
> character into a form feed. I've tried using
>
> tr "[\n*4]" "\f" < input-file > out_file
>
> but this doesn't work. Can anyone tell me what I'm doing wrong?
tr can only convert one character at a time. Try this:
awk '/^$/{n++;if(n==4) print "\f";next}{n=0;print}'

Re: Coverting newlines into form feed

am 09.04.2008 00:04:55 von sajohn52

On Apr 8, 2:24=A0pm, Bill Marcum wrote:
> On 2008-04-08, sajoh...@gmail.com wrote:
>
> > I have a text file with no page breaks but each page is broken up by 4
> > newline character. I'm having trouble converting these newline
> > character into aformfeed. I've tried using
>
> >tr"[\n*4]" "\f" < input-file > out_file
>
> > but this doesn't work. Can anyone tell me what I'm doing wrong?
>
> trcan only convert one character at a time. Try this:
> awk '/^$/{n++;if(n==4) print "\f";next}{n=3D0;print}'

Thanks Bill. Than worked great.

Re: Coverting newlines into form feed

am 09.04.2008 14:11:30 von gazelle

In article <34450557-bf53-4e12-9cda-bb34af3ea3c8@l64g2000hse.googlegroups.com>,
wrote:
>On Apr 8, 2:24 pm, Bill Marcum wrote:
>> On 2008-04-08, sajoh...@gmail.com wrote:
>>
>> > I have a text file with no page breaks but each page is broken up by 4
>> > newline character. I'm having trouble converting these newline
>> > character into aformfeed. I've tried using
>>
>> >tr"[\n*4]" "\f" < input-file > out_file
>>
>> > but this doesn't work. Can anyone tell me what I'm doing wrong?
>>
>> trcan only convert one character at a time. Try this:
>> awk '/^$/{n++;if(n==4) print "\f";next}{n=0;print}'

This fails if there is, say, 8 successive newlines
(because you don't reset n to 0 after printing the formfeed).

>Thanks Bill. Tha[t] worked great.

Here's another (cryptic) way:

/./ && !(n=0);++n == 4 {print "\f";n=0}

Re: Coverting newlines into form feed

am 09.04.2008 14:40:22 von Ed Morton

On 4/9/2008 7:11 AM, Kenny McCormack wrote:
> In article <34450557-bf53-4e12-9cda-bb34af3ea3c8@l64g2000hse.googlegroups.com>,
> wrote:
>
>>On Apr 8, 2:24 pm, Bill Marcum wrote:
>>
>>>On 2008-04-08, sajoh...@gmail.com wrote:
>>>
>>>
>>>>I have a text file with no page breaks but each page is broken up by 4
>>>>newline character. I'm having trouble converting these newline
>>>>character into aformfeed. I've tried using
>>>
>>>>tr"[\n*4]" "\f" < input-file > out_file
>>>
>>>>but this doesn't work. Can anyone tell me what I'm doing wrong?
>>>
>>>trcan only convert one character at a time. Try this:
>>>awk '/^$/{n++;if(n==4) print "\f";next}{n=0;print}'
>>
>
> This fails if there is, say, 8 successive newlines
> (because you don't reset n to 0 after printing the formfeed).
>
>
>>Thanks Bill. Tha[t] worked great.
>
>
> Here's another (cryptic) way:
>
> /./ && !(n=0);++n == 4 {print "\f";n=0}
>

That would count empty lines, not newline characters. With GNU awk:

gawk -v RS='\n\n\n\n' -v ORS='\f' '1' file

Regards,

Ed.

Re: Coverting newlines into form feed

am 09.04.2008 15:15:29 von Ed Morton

On 4/9/2008 7:40 AM, Ed Morton wrote:
>
> On 4/9/2008 7:11 AM, Kenny McCormack wrote:
>
>>In article <34450557-bf53-4e12-9cda-bb34af3ea3c8@l64g2000hse.googlegroups.com>,
>> wrote:
>>
>>
>>>On Apr 8, 2:24 pm, Bill Marcum wrote:
>>>
>>>
>>>>On 2008-04-08, sajoh...@gmail.com wrote:
>>>>
>>>>
>>>>
>>>>>I have a text file with no page breaks but each page is broken up by 4
>>>>>newline character. I'm having trouble converting these newline
>>>>>character into aformfeed. I've tried using
>>>>
>>>>>tr"[\n*4]" "\f" < input-file > out_file
>>>>
>>>>>but this doesn't work. Can anyone tell me what I'm doing wrong?
>>>>
>>>>trcan only convert one character at a time. Try this:
>>>>awk '/^$/{n++;if(n==4) print "\f";next}{n=0;print}'
>>>
>>This fails if there is, say, 8 successive newlines
>>(because you don't reset n to 0 after printing the formfeed).
>>
>>
>>
>>>Thanks Bill. Tha[t] worked great.
>>
>>
>>Here's another (cryptic) way:
>>
>>/./ && !(n=0);++n == 4 {print "\f";n=0}
>>
>
>
> That would count empty lines, not newline characters. With GNU awk:
>
> gawk -v RS='\n\n\n\n' -v ORS='\f' '1' file

To avoid the trailing FF the above would enforce:

gawk -v RS='\n\n\n\n' '{ORS=(RT?"\f":"")}1' file

and if you really want 4 empty lines instead of 4 newlines just add an extra
newling to the RS to represent the end of the line before the 4 empty lines:

gawk -v RS='\n\n\n\n\n' '{ORS=(RT?"\f":"")}1' file

The above won't convert 4 newlines at the start of the file to a FF since there
is no line before the 4 empty lines. In the unlikely event that that's a
problem, let us know...

Regards,

Ed.

Re: Coverting newlines into form feed

am 09.04.2008 15:49:45 von gazelle

In article <47FCB936.9040702@lsupcaemnt.com>,
Ed Morton wrote:
....
>That would count empty lines, not newline characters. With GNU awk:

It's the same thing.

Except maybe at the end of the file. And, in that case (see overall
problem context), it doesn't matter (and in fact, would be a bad thing).

Re: Coverting newlines into form feed

am 09.04.2008 16:19:07 von Ed Morton

On 4/9/2008 8:49 AM, Kenny McCormack wrote:
> In article <47FCB936.9040702@lsupcaemnt.com>,
> Ed Morton wrote:
> ...
>
>>That would count empty lines, not newline characters. With GNU awk:
>
>
> It's the same thing.

No, counting 4 consecutive newline characters lines means counting 3 empty
lines, not 4:

-----------
foo\n 1
\n 2
\n 3
\n 4
bar\n
-----------

Ed.