A sed question 
Author Message
 A sed question

Quote:
Gora writes:


:
:
: >I have a situation with sed where I would like to delete
: >several lines of text based on the content of one of them.
: >My data comes as a stream of blocks in the form:
:
: > header line
: > <body line1>
: > <body line2>
: > ...
: > <body line3>
: > footer line
:
:
: >I would like to be able to delete the entire block
: >if any of the text within it matches a regexp
:
: >Is there an easy way to do it ?
:
: Sure. Save the following to a file called, say, "myscript."
:
: /start/{N
: N
: N
: N
: /reg_exp/d
: }

[deleted]

why not awk ?

/usr/bin/awk '
/^header line$/ {
        while( $0 !~ /^footer line$/ )
                getline
        continue

Quote:
}

{
        print
Quote:
}

'

the number of lines between /^header line$/ and /^footer line$/
does not matter at all. but the /^footer line _must_ exist
or you must check the return code of getline (to avoid an
infinite loop).

Jacek Margos
-------------------------------------------------------
-------------------------------------------------------
-------------------------------------------------------
-------------------------------------------------------



Fri, 26 Feb 1999 03:00:00 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. How to do this.. (SED question)

2. a sed question

3. SED question

4. Sed Question

5. Urgent VI/SED question

6. This might be a sed question

7. sed question

8. awk vs. sed question

9. A sed question

10. sed question: unreliable "/^$/d" ?

11. Newbie awk (sed??) question, regular expressions

12. Awk/Sed Filehandler question

 

 
Powered by phpBB® Forum Software