Re: [gentoo-user] OT awk question
On Fri, Jan 19, 2018 at 12:13 AM, Adam Carterwrote: > On Wed, Jan 17, 2018 at 6:16 PM, Alexander Kapshuk > wrote: >> >> On Wed, Jan 17, 2018 at 3:49 AM, Adam Carter >> wrote: >> > I'm using this to grab a section of text across multiple lines, how do i >> > get >> > it to exit after the first match? >> > >> > awk '/foo/,/bar/' >> >> See if this works for you: >> awk '/foo/,/bar/{print;if(/bar/)exit}' file >> sed '/foo/,/bar/!d;/bar/q' file >> > The awk line works. I didnt try the sed line. Thanks! Good to hear. Thanks for letting us know. The sed line is identical in operation to the awk one: (1). Delete anything that's not in the range of lines from /foo/ to /bar/; (2). Print the lines that match the range specified; (3). Quit processing further lines of input on finding the first occurrence of /bar/;
Re: [gentoo-user] OT awk question
On Wed, Jan 17, 2018 at 6:16 PM, Alexander Kapshuk < alexander.kaps...@gmail.com> wrote: > On Wed, Jan 17, 2018 at 3:49 AM, Adam Carter> wrote: > > I'm using this to grab a section of text across multiple lines, how do i > get > > it to exit after the first match? > > > > awk '/foo/,/bar/' > > See if this works for you: > awk '/foo/,/bar/{print;if(/bar/)exit}' file > sed '/foo/,/bar/!d;/bar/q' file > > The awk line works. I didnt try the sed line. Thanks!
Re: [gentoo-user] OT awk question
On Wed, Jan 17, 2018 at 3:49 AM, Adam Carterwrote: > I'm using this to grab a section of text across multiple lines, how do i get > it to exit after the first match? > > awk '/foo/,/bar/' See if this works for you: awk '/foo/,/bar/{print;if(/bar/)exit}' file sed '/foo/,/bar/!d;/bar/q' file
[gentoo-user] OT awk question
I'm using this to grab a section of text across multiple lines, how do i get it to exit after the first match? awk '/foo/,/bar/'