Xref: utzoo comp.unix.wizards:25634 comp.unix.shell:2194 Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!mips!ultra!marc From: marc@mercutio.ultra.com (Marc Kwiatkowski {Host Software-AIX}) Newsgroups: comp.unix.wizards,comp.unix.shell Subject: Re: easy for some Message-ID: <1991May15.221607.1098@ultra.com> Date: 15 May 91 22:16:07 GMT References: <6686@male.EBay.Sun.COM> <574@appserv.Eng.Sun.COM> <1991May9.153351.1754@colorado.edu> <1991May9.185503.325@jpl-devvax.jpl.nasa.gov> Sender: marc@ultra.com (Marc Kwiatkowski {Host Software-AIX}) Followup-To: comp.unix.shell Distribution: comp Organization: Ultra Network Technologies Lines: 58 In-Reply-To: lwall@jpl-devvax.jpl.nasa.gov's message of 9 May 91 18:55:03 GMT In article <1991May9.185503.325@jpl-devvax.jpl.nasa.gov> lwall@jpl-devvax.jpl.nasa.gov (Larry Wall) writes: > In article <1991May9.153351.1754@colorado.edu> lewis@tramp.Colorado.EDU (LEWIS WILLIAM M JR) writes: > : In article <574@appserv.Eng.Sun.COM> lm@slovax.Eng.Sun.COM (Larry McVoy) writes: > : >matthew@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@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@ultra.com 101 Daggett Drive uucp: ...!ames!ultra!marc San Jose, CA 95134 USA