Getting rid of text in a file

Getting rid of text in a file

Post by springfiel » Sun, 02 Feb 2003 00:21:11



Hi,

When my G/F sends me emails from work there is a disclaimer at the
bottom that is starting to annoy me. It is always contained between
rows of asterisks like this:

*****...***** (there is 80 of them)
lines
of
boring
text
*****...***** (80 of these too)

I would like to make a procmail rule to rid me of these messages but
don't have a clue how to do it. I can do the procmail stuff, it's the
shell bit I don't have a clue with!

How could I remove this block of text?

Thanks allot
Phil Jackson

 
 
 

Getting rid of text in a file

Post by Barry Margoli » Sun, 02 Feb 2003 00:34:34




>Hi,

>When my G/F sends me emails from work there is a disclaimer at the
>bottom that is starting to annoy me. It is always contained between
>rows of asterisks like this:

>*****...***** (there is 80 of them)
>lines
>of
>boring
>text
>*****...***** (80 of these too)

>I would like to make a procmail rule to rid me of these messages but
>don't have a clue how to do it. I can do the procmail stuff, it's the
>shell bit I don't have a clue with!

>How could I remove this block of text?

sed '/^\*\*\*\**$/,/^\*\*\*\**$/d'

This will remove any block of lines between rows of at least 4 asterisks
(you can increase the number to make false positives less likely).

--

Genuity, Woburn, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.

 
 
 

Getting rid of text in a file

Post by Bill K » Sun, 02 Feb 2003 00:55:58




> Hi,

> When my G/F sends me emails from work there is a disclaimer at the
> bottom that is starting to annoy me. It is always contained between rows
> of asterisks like this:

> *****...***** (there is 80 of them)
> lines
> of
> boring
> text
> *****...***** (80 of these too)

> I would like to make a procmail rule to rid me of these messages but
> don't have a clue how to do it. I can do the procmail stuff, it's the
> shell bit I don't have a clue with!

> How could I remove this block of text?

I don't know for sure if this will work, but you can pipe messages
through a command by making the command a mail alias. You might be able
to filter out the unwanted text with sed.

man aliases

 
 
 

Getting rid of text in a file

Post by William Par » Sun, 02 Feb 2003 08:48:34





>>*****...***** (there is 80 of them)
>>lines
>>of
>>boring
>>text
>>*****...***** (80 of these too)
> sed '/^\*\*\*\**$/,/^\*\*\*\**$/d'

> This will remove any block of lines between rows of at least 4 asterisks
> (you can increase the number to make false positives less likely).

Or, OP can type the 80 stars in full.  :-)

--

Linux solution for data management and processing.

 
 
 

Getting rid of text in a file

Post by bd » Mon, 03 Feb 2003 04:25:13


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1


> Hi,

> When my G/F sends me emails from work there is a disclaimer at the
> bottom that is starting to annoy me. It is always contained between
> rows of asterisks like this:

> *****...***** (there is 80 of them)
> lines
> of
> boring
> text
> *****...***** (80 of these too)

> I would like to make a procmail rule to rid me of these messages but
> don't have a clue how to do it. I can do the procmail stuff, it's the
> shell bit I don't have a clue with!

> How could I remove this block of text?

> Thanks allot
> Phil Jackson

I don't know about you, but I'd do it in perl:
#!/usr/bin/perl -w
use strict;
use diagnostics;

while (my $line = <>){
        if($line =~ /[*]{80}/){
                exit 0;
        }
        print $line;

Quote:}

Pipe the message in, it'll output until the first line containing 80
asterisks.

- --
Replace spamtrap with bd to reply.
QOTD:
        "I used to be an idealist, but I got mugged by reality."

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (GNU/Linux)

iD8DBQE+PB31x533NjVSos4RAjXQAKCR2QaFn4ZCe+R5f82s5VccfmI5awCglUaA
EZkAztJyQ6yQyvjZZOOwcL0=
=k2mQ
-----END PGP SIGNATURE-----

 
 
 

Getting rid of text in a file

Post by those who know me have no need of my nam » Mon, 03 Feb 2003 12:50:46


in comp.unix.shell i read:

Quote:>> *****...***** (there is 80 of them)
>> lines
>> of
>> boring
>> text
>> *****...***** (80 of these too)
>> How could I remove this block of text?
>Pipe the message in, it'll output until the first line containing 80
>asterisks.

not quite what the op desires.

--
bringing you boring signatures for 17 years

 
 
 

Getting rid of text in a file

Post by bd » Tue, 04 Feb 2003 05:40:16


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1


Quote:> in comp.unix.shell i read:

>>> *****...***** (there is 80 of them)
>>> lines
>>> of
>>> boring
>>> text
>>> *****...***** (80 of these too)

>>> How could I remove this block of text?

>>Pipe the message in, it'll output until the first line containing 80
>>asterisks.

> not quite what the op desires.

Oh, I see. How about this:

#!/usr/bin/perl -w
use strict;

my $toggle = 0;
while (my $line = <>){
        if($line =~ /[*]{80}/){
                $toggle = 1 - $toggle;
                next;
        }
        if($toggle){
                next;
        }
        print $line;

Quote:}

- --
Replace spamtrap with bd to reply.
How sharper than a hound's tooth it is to have a thankless serpent.

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (GNU/Linux)

iD8DBQE+PYHnx533NjVSos4RAm+yAJ4vVf1RonQgt6iQM40LISCfZ/Mm+wCfWw46
zEtwLyR6MfG86hvoxvA/Gh8=
=3PtG
-----END PGP SIGNATURE-----

 
 
 

Getting rid of text in a file

Post by John W. Krah » Tue, 04 Feb 2003 09:02:35



> >>> *****...***** (there is 80 of them)
> >>> lines
> >>> of
> >>> boring
> >>> text
> >>> *****...***** (80 of these too)

> >>> How could I remove this block of text?

> Oh, I see. How about this:

> #!/usr/bin/perl -w
> use strict;

> my $toggle = 0;
> while (my $line = <>){
>         if($line =~ /[*]{80}/){
>                 $toggle = 1 - $toggle;

                  ^^^^^^^^^^^^^^^^^^^^^
The idiomatic way to do this in perl (and C) is to use logical negation.

                 $toggle = ! $toggle;

Quote:>                 next;
>         }
>         if($toggle){
>                 next;
>         }
>         print $line;
> }

The idiomatic way to write this in perl is to use the range operator in
scalar context.

#!/usr/bin/perl -w
use strict;

while ( <> ) {
    next if /^\*{80}$/ ... /^\*{80}$/;
    print;
    }

__END__

John
--
use Perl;
program
fulfillment