Go to Google Groups Home  
Web    Images    Groups    News    Froogle    more »
  Advanced Groups Search
  Preferences    
View with framesSort by reply  Sorted by date
Messages 1-10 from thread "Sed question"
Next 10
Jump to [ End of thread ]

Message 1 in thread
From: Susan Maxwell (smaxwell@hpcuhc.HP.COM)
Subject: SED Question
 
View this article only
Newsgroups: comp.editors
Date: 1989-04-10 17:43:33 PST
Got a sed question for you:  I'm creating a sed filter to mask out and
delete unwanted characters in a trace file.  I'm having trouble with this
configuration:

        LINE I:    PROMPT>
        LINE I+1:  >
        LINE I+2:  <

Whenever I see this series, I want to delete ALL THREE lines.  I can't
create a pattern /PROMPT\>\\n\>\\n\</d   as far as I can tell, because
sed won't allow patterns to span lines.  Is there a way to do this, without
resorting to awk or ed?   

Susan Maxwell
Message 2 in thread
From: 3929] (uucibg@sw1e.UUCP)
Subject: Re: SED Question
 
View this article only
Newsgroups: comp.editors
Date: 1989-04-11 09:29:02 PST
In article<2360001@hpcuhc.HP.COM> smaxwell@hpcuhc.HP.COM (Susan Maxwell) writes:
>Got a sed question for you:  I'm creating a sed filter to mask out and
>delete unwanted characters in a trace file.  I'm having trouble with this
>configuration:
>        LINE I:    PROMPT>
>        LINE I+1:  >
>        LINE I+2:  <
>Whenever I see this series, I want to delete ALL THREE lines.  I can't
>create a pattern /PROMPT\>\\n\>\\n\</d   as far as I can tell, because
>sed won't allow patterns to span lines.  Is there a way to do this, without
>resorting to awk or ed?   
>
>Susan Maxwell

cat "file to filter" | sed -e "/^PROMPT>/,/^</d"

should do the trick.  It says:  delete (inclusive) all lines from one which
starts with the text "PROMPT>" and one which starts with the text "<".
Note that you can do

sed -e "/^PROMPT>$/,/^<$/d" if you need the lines to contain exactly that
text.


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 3 in thread
From: HansM (hm@uva.UUCP)
Subject: Re: SED Question
 
View this article only
Newsgroups: comp.editors
Date: 1989-04-11 10:37:50 PST
In article <2360001@hpcuhc.HP.COM> smaxwell@hpcuhc.HP.COM (Susan Maxwell) writes:
>
>Got a sed question for you:  I'm creating a sed filter to mask out and
>delete unwanted characters in a trace file.  I'm having trouble with this
>configuration:
>
>        LINE I:    PROMPT>
>        LINE I+1:  >
>        LINE I+2:  <
>
>Whenever I see this series, I want to delete ALL THREE lines.  I can't
>create a pattern /PROMPT\>\\n\>\\n\</d   as far as I can tell, because
>sed won't allow patterns to span lines.  Is there a way to do this, without
>resorting to awk or ed?   
>
>Susan Maxwell


How about "sed -f sedscript", where the file named sedscript contains:

/PROMPT>/ {
     N
     /PROMPT>\n>/{
     N
     /PROMPT>\n>\n</d
   }
   }

Hope this is what you are looking for.

--
Hans Mulder mcvax!uva!hm hm%uva@hp4nl.nluug.nl
Message 4 in thread
From: Joe Grace (jgrace@bbn.com)
Subject: Re: SED Question
 
View this article only
Newsgroups: comp.editors
Date: 1989-04-11 17:11:35 PST
In article <2360001@hpcuhc.HP.COM> smaxwell@hpcuhc.HP.COM (Susan Maxwell) writes:
>
>Got a sed question for you:  I'm creating a sed filter to mask out and
>delete unwanted characters in a trace file.  I'm having trouble with this
>configuration:
>
>        LINE I:    PROMPT>
>        LINE I+1:  >
>        LINE I+2:  <
>
>Whenever I see this series, I want to delete ALL THREE lines.  I can't
>create a pattern /PROMPT\>\\n\>\\n\</d   as far as I can tell, because
>sed won't allow patterns to span lines.  Is there a way to do this, without
>resorting to awk or ed?   
>
>Susan Maxwell

Yes, there is a way to get sed to do this, but you have to be
wary of sed's shortcomings.

Try:
----
#! /bin/sh

(cat trace.out;  echo "SomeUniqueID")  \
| sed  \
    -e '/^PROMPT>$/{'  \
      -e 'N'  \
      -e '/\nSomeUniqueID$/{;s@\nSomeUniqueID$@@;q;}'  \
      -e 'N'  \
      -e '/\nSomeUniqueID$/{;s@\nSomeUniqueID$@@;q;}'  \
      -e '/^PROMPT>\n>\n<$/d'  \
    -e '}'  \
    -e '/^SomeUniqueID$/d'

If sed had a way of handling an EOF without quitting, the
SomeUniqueID would be unnecessary.  As sed is, the SomeUniqueID
is used to avoid losing lines which start out the same as your
pattern but which do not fully match your pattern --- and which
you therefore want to keep.

Cheers,

= Joe =
Joe Grace
ARPA: jgrace@bbn.com
UUCP: {harvard,husc6,decvax,etc.}!bbn!jgrace
Message 5 in thread
From: John Rupley (rupley@arizona.edu)
Subject: Re: SED Question
 
View this article only
Newsgroups: comp.editors
Date: 1989-04-12 03:47:42 PST
In article <38564@bbn.COM>, jgrace@bbn.com (Joe Grace) writes:
> In article <2360001@hpcuhc.HP.COM> smaxwell@hpcuhc.HP.COM (Susan Maxwell) writes:
> >Got a sed question for you:  I'm creating a sed filter to mask out and
> >delete unwanted characters in a trace file.  I'm having trouble with this
> >configuration:
> >        LINE I:    PROMPT>
> >        LINE I+1:  >
> >        LINE I+2:  <
> >Whenever I see this series, I want to delete ALL THREE lines.  I can't
> >create a pattern /PROMPT\>\\n\>\\n\</d   as far as I can tell, because
> >sed won't allow patterns to span lines.  Is there a way to do this, without
> >resorting to awk or ed?   
> 
> Yes, there is a way to get sed to do this, but you have to be
> wary of sed's shortcomings.
> 
> Try:
> ----
> #! /bin/sh
> 
> (cat trace.out;  echo "SomeUniqueID")  \
> | sed  \
>     -e '/^PROMPT>$/{'  \
>       -e 'N'  \
>       -e '/\nSomeUniqueID$/{;s@\nSomeUniqueID$@@;q;}'  \
>       -e 'N'  \
>       -e '/\nSomeUniqueID$/{;s@\nSomeUniqueID$@@;q;}'  \
>       -e '/^PROMPT>\n>\n<$/d'  \
>     -e '}'  \
>     -e '/^SomeUniqueID$/d'
> 
> If sed had a way of handling an EOF without quitting, the            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> SomeUniqueID would be unnecessary.  As sed is, the SomeUniqueID
> is used to avoid losing lines which start out the same as your
> pattern but which do not fully match your pattern --- and which
> you therefore want to keep.

Sed can check for EOF, I believe, and fairly simply, by use of the
address "$", for last line of file.  The following script should take
care of the last line problem, as well as some additional but probably
not all other abnormalities. 

sed -e '/^PROMPT>$/{
 : restart
 /^PROMPT>$/{
  h
  $q

Read the rest of this message... (26 more lines)

Message 6 in thread
From: Joe Grace (jgrace@bbn.com)
Subject: Re: SED Question
 
View this article only
Newsgroups: comp.editors
Date: 1989-04-12 10:03:25 PST

John is definitely right about the "$" and bugs, even his sed style is
better (Thanks!).  But I just thought about another way you *could* do
it using the (new :-) "$" feature assuming your sed hold buffer is big
enough (likely, it won't be :-( :-( :-().  But this script is the
simplest so far, so... 

  sed -n -e 'H;${;x;s@^\(.\)\(.*\)@\2\1@;s@PROMPT>\n>\n<\n@@g;s@\n$@@;p;}'
  
= Joe =

Joe Grace
ARPA: jgrace@bbn.com
UUCP: {harvard,husc6,decvax,etc.}!bbn!jgrace
Message 7 in thread
From: Susan Maxwell (smaxwell@hpcuhc.HP.COM)
Subject: Re: SED Question
 
View this article only
Newsgroups: comp.editors
Date: 1989-04-14 09:44:38 PST
/ hpcuhc:comp.editors / smaxwell@hpcuhc.HP.COM (Susan Maxwell) /  5:43 pm  Apr 10, 1989 /

Got a sed question for you:  I'm creating a sed filter to mask out and
delete unwanted characters in a trace file.  I'm having trouble with this
configuration:

        LINE I:    PROMPT>
        LINE I+1:  >
        LINE I+2:  <

Whenever I see this series, I want to delete ALL THREE lines.  I can't
create a pattern /PROMPT\>\\n\>\\n\</d   as far as I can tell, because
sed won't allow patterns to span lines.  Is there a way to do this, without
resorting to awk or ed?   

Susan Maxwell

----------
Message 8 in thread
From: John Hevelin (jackh%twinpeaks@Sun.COM)
Subject: Re: SED Question
 
View this article only
Newsgroups: comp.editors
Date: 1989-04-16 23:38:55 PST
This works for me.  Put the following in a script
and call with "sed -f script file"


/PROMPT>/ {
N
/PROMPT>\n[^>]/ {
P
D
p
b
}
/PROMPT>\n>/ {
N
/PROMPT>\n>\n[^<]/ {
P
D
P
D
p
b
}
/PROMPT>\n>\n</ {
s/\n//g
d
}
}
}
Message 9 in thread
From: merlin@violet.berkeley.edu (merlin@violet.berkeley.edu)
Subject: Re: SED Question
 
View this article only
Newsgroups: comp.editors
Date: 1989-04-17 17:44:04 PST
I think this does it (script run with "-f"):

/PROMPT>/ {
$b eof
N
$b eof
N
/PROMPT>\n>\n</ {
d
b
}
p
d
} b
: eof
p
d
q
Message 10 in thread
From: John Rupley (rupley@arizona.edu)
Subject: Re: SED Question
 
View this article only
Newsgroups: comp.editors
Date: 1989-04-17 23:23:11 PST
In article <23224@agate.BERKELEY.EDU>, merlin@violet.berkeley.edu writes:
> I think this does it (script run with "-f"):
> 
> /PROMPT>/ {
> $b eof
> N
> $b eof
> N
> /PROMPT>\n>\n</ {
> d
> b
> }
> p
> d
> } b
> : eof
> p
> d
> q

No cigar - try:

xxxPROMPT>
>
<
PROMPT>
> PROMPT>
>
<

The script deletes what it shouldn't and doesn't what it should.

At least three previous postings give apparently correct solutions.

John Rupley
rupley!local@megaron.arizona.edu

Next 10
Jump to [ End of thread ]


©2004 Google