easy for some

Marc Kwiatkowski {Host Software-AIX} marc at mercutio.ultra.com
Thu May 16 08:16:07 AEST 1991


In article <1991May9.185503.325 at jpl-devvax.jpl.nasa.gov> lwall at jpl-devvax.jpl.nasa.gov (Larry Wall) writes:
>   In article <1991May9.153351.1754 at colorado.edu> lewis at tramp.Colorado.EDU (LEWIS WILLIAM M JR) writes:
>   : In article <574 at appserv.Eng.Sun.COM> lm at slovax.Eng.Sun.COM (Larry McVoy) writes:
>   : >matthew at gizmo.UK.Sun.COM (Matthew Buller - Sun EHQ - MIS) writes:
>   : >> problem: to extract text between start and end patterns in a file
>   : ... more problem description
>   : >/bin/sh, usage shellscript start_pat stop_pat [files...]
>   : >
>   : ... complex shell and perl programs to do
>   : 
>   : 	sed -n '/pattern1/,/pattern2/p' source_file > new_file

>   Here's the perl equivalent of what you said:
>
>       perl -ne 'print if /pattern1/../pattern2/' source_file >new_file
>
>   When using Perl to do the other thing, I personally prefer a straightforward
>   approach:

Ahh.  In grand c.u.w tradition the lesser sin of a non-wizardly question
is met with the greater sin of slightly-correct to downright wrong
answers.  I know this isn't the right newsgroup, but the posters
question hasn't been answered.  The sed suggestions are all wet.
The perl one will work and in terms of execution and readability
is probably the best, but the original poster stated that he 
preferred an answer for /bin/sh.  I am surprised noone suggested 
something like the following answer:

	cat foo | sed -n '
	:lbl00
	    /pattern00/ {
	:lbl01
		n
		/pattern01/ {
			b lbl00
		}
		p
		b lbl01
	}'

The above will filter multiple instances of /pattern00/..../pattern01/.
If only one is desired, replace 'b lbl00' with 'q'.

Note follow-up.  sed, a utility more sinned against than sinning.
--
	------------------------------------------------------------------
	Marc P. Kwiatkowski			Ultra Network Technologies
	Internet: marc at ultra.com		101 Daggett Drive
	uucp: ...!ames!ultra!marc		San Jose, CA 95134 USA
	telephone: 408 922 0100 x249

	Ignore the following signature.
-- 
	------------------------------------------------------------------
	Marc P. Kwiatkowski			Ultra Network Technologies
	Internet: marc at ultra.com		101 Daggett Drive
	uucp: ...!ames!ultra!marc		San Jose, CA 95134 USA



More information about the Comp.unix.wizards mailing list