Go to Google Groups Home  
Web    Images    Groups    News    Froogle    more »
  Advanced Groups Search
  Preferences    
View with framesSorted by reply  Sort by date
All messages from thread "Re^2: SED Question"
  
Message 1 in thread
From: Maarten Litmaath (maart@cs.vu.nl)
Subject: Re^2: SED Question
 
View this article only
Newsgroups: comp.editors, comp.unix.questions
Date: 1989-04-12 14:03:59 PST
jgrace@bbn.com (Joe Grace) writes:
\...
\Yes, there is a way to get sed to do this, but you have to be
\wary of sed's shortcomings.

[shell script workaround deleted]

\If sed had a way of handling an EOF without quitting, the
\[workaround would be unnecessary] [...]

My first sed attempt can easily be fixed to handle partial matches at EOF
properly:

sed -n '
        /^PROMPT>$/{
  $p
                h
                n
                H
                /^>$/{
   $b eof
                        n
                        /^<$/b
                        H
                }
  : eof
                g
        }
        p
'
-- 
 "If it isn't aesthetically pleasing, |Maarten Litmaath @ VU Amsterdam:
  it's probably wrong." (jim@bilpin). |maart@cs.vu.nl, mcvax!botter!maart
Message 2 in thread
From: Leo de Wit (leo@philmds.UUCP)
Subject: Re: Re^2: SED Question
 
View this article only
Newsgroups: comp.editors, comp.unix.questions
Date: 1989-04-13 15:00:08 PST
In article <2292@solo11.cs.vu.nl> maart@cs.vu.nl (Maarten Litmaath) writes:
    []
|My first sed attempt can easily be fixed to handle partial matches at EOF
|properly:
|
|sed -n '
|        /^PROMPT>$/{
|  $p
|                h
|                n
|                H
|                /^>$/{
|   $b eof
|                        n
|                        /^<$/b
|                        H
|                }
|  : eof
|                g
|        }
|        p
|'

I think you'll need a third attempt 8-). It still doesn't handle correct
a series of lines like 

      PROMPT>
      PROMPT>
      >
      <

or one like

      PROMPT>
      >
      PROMPT>
      >
      <

Alternative:

sed -n '
: start
$p
$q
N
/^PROMPT>\n>\n<$/d
/\n[^\n]*\n/{
    P
    D
}
b start'

    Leo.
Message 3 in thread
From: 3929] (uucibg@sw1e.UUCP)
Subject: Re: Re^2: SED Question
 
View this article only
Newsgroups: comp.editors, comp.unix.questions
Date: 1989-04-14 20:40:40 PST
In article <1003@philmds.UUCP> leo@philmds.UUCP (Leo de Wit) writes:
=I think you'll need a third attempt 8-). It still doesn't handle correct
=a series of lines like 
=
=      PROMPT>
=      PROMPT>
=      >
=      <
=
=or one like
=
=      PROMPT>
=      >
=      PROMPT>
=      >
=      <
=
=Alternative:
=
=sed -n '
=: start
=$p
=$q
=N
=/^PROMPT>\n>\n<$/d
=/\n[^\n]*\n/{
=    P
=    D
=}
=b start'
=
=    Leo.

I think I may have missed a posting or two on this topic.  Could someone
please tell me why the following does not handle the problem:

cat myfile | sed -e '/^PROMPT>$/,/^<$/d'


Many thanks,

Brian R. Gilstrap                          Southwestern Bell Telephone
One Bell Center Rm 17-G-4                  ...!ames!killer!texbell!sw1e!uucibg
St. Louis, MO 63101                        ...!bellcore!texbell!sw1e!uucibg
(314) 235-3929
#include <std_disclaimers.h>
Message 4 in thread
From: John Rupley (rupley@arizona.edu)
Subject: Re: Re^2: SED Question
 
View this article only
Newsgroups: comp.editors, comp.unix.questions
Date: 1989-04-13 19:14:07 PST
In article <2292@solo11.cs.vu.nl>, maart@cs.vu.nl (Maarten Litmaath) writes:
> jgrace@bbn.com (Joe Grace) writes:

[the problem is to delete all three-line sequences:
  PROMPT>
  >
  <
]

> \...
> \Yes, there is a way to get sed to do this, but you have to be
> \wary of sed's shortcomings.
> 
> [shell script workaround deleted]
> 
> \If sed had a way of handling an EOF without quitting, the
> \[workaround would be unnecessary] [...]
> 
> My first sed attempt can easily be fixed to handle partial matches at EOF
> properly:

[sed script deleted]

Neat script (of course), but it still fails with a partial sequence
followed by a proper sequence, such as:

  PROMPT>
  > PROMPT>
  >
  <

The ``restart'' loop below takes care of it:

sed -n '
 : restart
 /^PROMPT>$/{
  h
  $p
  n
  /^>$/{
   H
   ${x;p;}
   n
   /^<$/d
  }
  x
  p
  x
  b restart
 }
 p
'

BTW -- the following one line Lex source does it all:

%%
PROMPT>\n>\n<\n  ;

and its hard to get the logic wrong (:-)!


John Rupley
rupley!local@megaron.arizona.edu
Message 5 in thread
From: Danny (danny@itm.UUCP)
Subject: Re: Re^2: SED Question
 
View this article only
Newsgroups: comp.editors, comp.unix.questions
Date: 1989-04-14 06:01:51 PST
Uh,

    Why not use the sed comma operator?  Like:
    
        sed '/^PROMPT>/,/^>/d' file
        
    I got the impression that the original poster didn't care WHAT
lay between the first and last match lines.

                                        Danny
-- 
    Daniel S. Cox
    (seismo!gatech!itm!danny)
  

©2004 Google