deleting text block 
Author Message
 deleting text block

Quote:

>We wish to remove blocks of text from mailing list digests; setting the
>"digest_rm_footer = test" in majordomo 1.94.5, where test.config defines
>the block of test as a footer, does not yield the desired result in the
>perl script that majordomo employs.

>Here is the text to be removed in a file "junk":

>#################################################
>To unsubscribe from this list send an email to

>"unsubscribe test" IN THE MESSAGE BODY.


>      to the entire list.
>#################################################

>We tried an file expression (test.sed) found in the sed FAQ, which
>*appears* to be constructed properly:

<snip>

Tony --

Here is _one_ way.  

#################### cut here #####################
#!/bin/sh
gawk '
BEGIN {

   PoundRegEx = "^\#+$"   # regex describing a line consisting of "#" chars
   InBlock    = 0

Quote:
}

{
   if ( match ( $0, PoundRegEx ) == 1 )
   {
      InBlock = (( InBlock == 0 ) ? 1 : 0 )
      next
   }

   if ( ! InBlock )
      print

#################### cut here #####################

This is the effect of the above script on your original article:
( I added the '^> ' to each line so's not to confuse nuz readers )

Note the block has been removed.

####################### cut here ###################

- Show quoted text -

Quote:
> Article: 13814 of comp.lang.awk
> Path: mindspring!news.mindspring.net!cpk-news-hub1.bbnplanet.com!news.gtei.net!nntp2.deja.com!nnrp1.deja.com!not-for-mail

> Newsgroups: comp.lang.awk,comp.lang.perl
> Subject: deleting text block
> Date: Thu, 30 Mar 2000 23:56:09 GMT
> Organization: Deja.com - Before you buy.
> Lines: 42

> NNTP-Posting-Host: 216.122.67.134
> X-Article-Creation-Date: Thu Mar 30 23:56:09 2000 GMT
> X-Http-User-Agent: Mozilla/4.7 [en] (X11; I; SunOS 5.7 sun4u)
> X-Http-Proxy: 1.0 x43.deja.com:80 (Squid/1.1.22) for client 216.122.67.134
> X-MyDeja-Info: XMYDJUIDynotssor
> Xref: mindspring comp.lang.awk:13814

> We wish to remove blocks of text from mailing list digests; setting the
> "digest_rm_footer = test" in majordomo 1.94.5, where test.config defines
> the block of test as a footer, does not yield the desired result in the
> perl script that majordomo employs.

> Here is the text to be removed in a file "junk":

> We tried an file expression (test.sed) found in the sed FAQ, which
> *appears* to be constructed properly:

> :t
> /#################################################/,/########################
> #########################/{
> /#################################################/! { N; b t; }
> /aug/s/^.*#################################################// }

> with the results:

> $ sed -f test.sed junk
> Unrecognized command:
> /#################################################/! { N; b t; }

> Is there a working awk/sed/perl expression to accomplish this task?

> -   tony

> Sent via Deja.com http://www.*-*-*.com/
> Before you buy.

####################### cut here ###################
--
------------------------------------------------------------

1111 Seacoast Dr.  Unit 41   |  home:   (619) 423-4451     |
Imperial Beach, CA   91932   |                             |


Thu, 19 Sep 2002 04:00:00 GMT  
 deleting text block

% Here is the text to be removed in a file "junk":

% #################################################
% To unsubscribe from this list send an email to
[...]
% #################################################

[attempt at a sed solution]

% /#################################################/,/########################
% #########################/{

This is a range

% /#################################################/! { N; b t; }

and this (because of the { above) should be a command which acts on every
line in that range.

You could do it in sed like this:

 sed -n '/^##*$/,/^##*$/ d; p'

that strips off everything between pairs of lines consisting only of
sharp signs, which could be hazerdous. Ranges don't work exactly the same
way in awk, so the obvious awk equivalent

 /^#+$/,/^#+$ { next }
 { print }

doesn't work. You could create your own range like this:

 /^#+$/ { strip = strip ? 0 : 1; next }
 !strip { print }

but this approach screws up the moment somebody puts ###### on a line in a
message. I'd test at least the first line of the part you want to strip out:

 /^#+$/ { save = $0
          getline
          if (/^To unsubscribe from this list/) {
             while (! /^#+$/)
               getline
             next
          }
          else
            print save
        }
 { print }
--

Patrick TJ McPhee
East York  Canada



Thu, 19 Sep 2002 04:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Delete Text Block Between a pair of Parenthesis

2. TextUndo in Tk800.015 is slow deleting blocks of text

3. How to delete a block of comment?

4. FAQ: How to match a block of text containing newlines

5. Counting blocks of text

6. Block text extraction

7. Calling function from text block

8. Extracting Blocks of text

9. methods to insert/substitute blocks of text?

10. Replacing blocks of text on-the-fly......

11. Multi-line blocks of text

12. matching a block of text through RE.

 

 
Powered by phpBB® Forum Software