Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Re: Another one-liner?

1 view
Skip to first unread message

Daniel Tiefnig

unread,
Jun 24, 2009, 11:04:55 AM6/24/09
to go...@perl.org
Phil Carmody wrote:
> I needed to remove blank-line-separated chunks of code from a text
> file if those chunks contained any lines which were 'too long'.
[...]
> If you think how little it does, it's got to be one-linerable, no?

Duh, wrong e-mail address, sorry if solutions show up twice now after a
while...

Should do the trick if paragraphs are separated by *empty* lines:

perl -00 -ne'/.{65535}/||print'

Here's one that does split on lines with whitespace too, but is much
less elegant than my first one:

perl -0777 -F'(?<=\n)\s*(?=\n)' -ane'/.{65535}/||print for@F'

Maybe one can save one or the other stroke with a smarter solution of
the newline issue...

lg,
daniel

Jasper

unread,
Jun 24, 2009, 11:26:05 AM6/24/09
to go...@perl.org
2009/6/24 Daniel Tiefnig <dan...@gmx.at>:

>
>  perl -00 -ne'/.{65535}/||print'
>

of course becomes

perl -00 -pe'$_ x=!/.{65535}/'

--
Jasper

Eirik Berg Hanssen

unread,
Jun 24, 2009, 12:59:41 PM6/24/09
to yan...@babyl.dyndns.org, Jasper, go...@perl.org
yan...@babyl.dyndns.org writes:

> On Wed, Jun 24, 2009 at 04:26:05PM +0100, Jasper wrote:
>> 2009/6/24 Daniel Tiefnig <dan...@gmx.at>:
>> >
>> > ?perl -00 -ne'/.{65535}/||print'


>> >
>>
>> of course becomes
>>
>> perl -00 -pe'$_ x=!/.{65535}/'
>

> I'm probably overlooking something silly, but
>
> perl -O0 -pe's/.{65535,}//'
>
> ?

Newlines.


Eirik
--
Perl programmers do it more than one way

yan...@babyl.dyndns.org

unread,
Jun 24, 2009, 1:51:07 PM6/24/09
to Jasper, go...@perl.org
On Wed, Jun 24, 2009 at 04:26:05PM +0100, Jasper wrote:
> 2009/6/24 Daniel Tiefnig <dan...@gmx.at>:
> >
> > ?perl -00 -ne'/.{65535}/||print'

> >
>
> of course becomes
>
> perl -00 -pe'$_ x=!/.{65535}/'

I'm probably overlooking something silly, but

perl -O0 -pe's/.{65535,}//'

?

Joy,
`/anick

Daniel Tiefnig

unread,
Jun 24, 2009, 1:43:32 PM6/24/09
to go...@perl.org
Eirik Berg Hanssen wrote:
>> I'm probably overlooking something silly, but
>>
>> perl -O0 -pe's/.{65535,}//'
>
> Newlines.

Besides that I'm getting "Can't do {n,m} with n > m in regex" for values
greater than 2^15 - 1 here.

br,
daniel

Daniel Tiefnig

unread,
Jun 24, 2009, 10:01:50 AM6/24/09
to go...@perl.org
Phil Carmody wrote:
> I needed to remove blank-line-separated chunks of code from a text
> file if those chunks contained any lines which were 'too long'.
[...]
> If you think how little it does, it's got to be one-linerable, no?

Here's one that does split on lines with whitespace too, but is much

Daniel Tiefnig

unread,
Jun 24, 2009, 9:38:06 AM6/24/09
to go...@perl.org
Phil Carmody wrote:
> I needed to remove blank-line-separated chunks of code from a text
> file if those chunks contained any lines which were 'too long'.
[...]
> If you think how little it does, it's got to be one-linerable, no?

Should do the trick:

perl -00 -ne'/.{65535}/||print'

lg,
daniel

yan...@babyl.dyndns.org

unread,
Jun 25, 2009, 9:53:20 AM6/25/09
to Eirik Berg Hanssen, go...@perl.org
On Wed, Jun 24, 2009 at 06:59:41PM +0200, Eirik Berg Hanssen wrote:
> yan...@babyl.dyndns.org writes:
> > I'm probably overlooking something silly, but
> >
> > perl -O0 -pe's/.{65535,}//'
> >
> > ?
>
> Newlines.

Arrgh. I knew I was forgetting something. Darn, foiled again!

Joy,
`/anick

--

0 new messages