Need script to pluck lines of text from a file

Dan Messinger dan at scooter.rosemount.com
Thu Jul 5 23:12:08 AEST 1990


In article <8957 at rosevax.Rosemount.COM>, dan at scooter.rosemount.com (Dan
Messinger) writes:
|> In article <1990Jun30.180958.28569 at cbnewsd.att.com>,
|> jfb200 at cbnewsd.att.com (joseph.f.baugher) writes:
|> |> 
|> |> I am looking for a Shell script capable of doing the following job:
|> |> 
|> |> I have a file consisting of several dozen lines of text, as per example:
|> |> 
|> |> 		text in line 1
|> |> 		text in line 2
|> |> 		....
|> |> 		text in line n
|> |> 		startmarker
|> |> 		text in line n+1
|> |> 		text in line n+2
|> |> 		....
|> |> 	        ...
|> |> 		text in line n+m-1
|> |> 		endmarker
|> |> 		text in line n+m+1
|> |> 		text in line n+m+2
|> |> 		....
|> |> 	        ....
|> |> where startmarker and endmarker are lines of text with characteristic
|> |> markers in them which identify them as unique and different from
the others.
|> |> I want to be able to pipe the lines of text BETWEEN startmarker and
|> |> endmarker to another command for further processing.  Unfortunately,
|> I do not
|> |> know ahead of time what the numbers n and m are.
|> |> 
|> 
|> Sounds like a job for sed.
|> 
|> sed -n "/^startmarker/,/^endmarker/p"

I was informed of a problem with this sed command, in that it also prints the
start and end markers.  So I will try again.  sed doesn't support an offset
on an address pattern, but ex does.  I think this will do the trick.

ex - "+/^startmark/+1,/^endmark/-1 p|q" file

It is slightly limited in that the source text must be in a file, and not
piped into ex.  But the output can be piped to another command as Joseph
specified.

Dan Messinger
dan at scooter.rosemount.com



More information about the Comp.unix.questions mailing list