* [gentoo-user] OT awk question
@ 2018-01-17 1:49 Adam Carter
2018-01-17 3:19 ` [gentoo-user] " Ian Zimmerman
2018-01-17 7:16 ` [gentoo-user] " Alexander Kapshuk
0 siblings, 2 replies; 5+ messages in thread
From: Adam Carter @ 2018-01-17 1:49 UTC (permalink / raw
To: gentoo-user
[-- Attachment #1: Type: text/plain, Size: 130 bytes --]
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/'
[-- Attachment #2: Type: text/html, Size: 287 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
* [gentoo-user] Re: OT awk question
2018-01-17 1:49 [gentoo-user] OT awk question Adam Carter
@ 2018-01-17 3:19 ` Ian Zimmerman
2018-01-17 7:16 ` [gentoo-user] " Alexander Kapshuk
1 sibling, 0 replies; 5+ messages in thread
From: Ian Zimmerman @ 2018-01-17 3:19 UTC (permalink / raw
To: gentoo-user
On 2018-01-17 12:49, 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/'
I don't think I ever tried to match multiple line range. I would do it
like this:
/foo/ { selecting = 1; }
( selecting == 1 ) { print $0; }
/bar/ { if (selecting) exit 0; }
--
Please don't Cc: me privately on mailing lists and Usenet,
if you also post the followup to the list or newsgroup.
To reply privately _only_ on Usenet, fetch the TXT record for the domain.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [gentoo-user] OT awk question
2018-01-17 1:49 [gentoo-user] OT awk question Adam Carter
2018-01-17 3:19 ` [gentoo-user] " Ian Zimmerman
@ 2018-01-17 7:16 ` Alexander Kapshuk
2018-01-18 22:13 ` Adam Carter
1 sibling, 1 reply; 5+ messages in thread
From: Alexander Kapshuk @ 2018-01-17 7:16 UTC (permalink / raw
To: Gentoo mailing list
On Wed, Jan 17, 2018 at 3:49 AM, Adam Carter <adamcarter3@gmail.com> 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
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [gentoo-user] OT awk question
2018-01-17 7:16 ` [gentoo-user] " Alexander Kapshuk
@ 2018-01-18 22:13 ` Adam Carter
2018-01-19 4:20 ` Alexander Kapshuk
0 siblings, 1 reply; 5+ messages in thread
From: Adam Carter @ 2018-01-18 22:13 UTC (permalink / raw
To: gentoo-user
[-- Attachment #1: Type: text/plain, Size: 486 bytes --]
On Wed, Jan 17, 2018 at 6:16 PM, Alexander Kapshuk <
alexander.kapshuk@gmail.com> wrote:
> On Wed, Jan 17, 2018 at 3:49 AM, Adam Carter <adamcarter3@gmail.com>
> 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!
[-- Attachment #2: Type: text/html, Size: 952 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [gentoo-user] OT awk question
2018-01-18 22:13 ` Adam Carter
@ 2018-01-19 4:20 ` Alexander Kapshuk
0 siblings, 0 replies; 5+ messages in thread
From: Alexander Kapshuk @ 2018-01-19 4:20 UTC (permalink / raw
To: Gentoo mailing list
On Fri, Jan 19, 2018 at 12:13 AM, Adam Carter <adamcarter3@gmail.com> wrote:
> On Wed, Jan 17, 2018 at 6:16 PM, Alexander Kapshuk
> <alexander.kapshuk@gmail.com> wrote:
>>
>> On Wed, Jan 17, 2018 at 3:49 AM, Adam Carter <adamcarter3@gmail.com>
>> 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/;
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2018-01-19 4:21 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-01-17 1:49 [gentoo-user] OT awk question Adam Carter
2018-01-17 3:19 ` [gentoo-user] " Ian Zimmerman
2018-01-17 7:16 ` [gentoo-user] " Alexander Kapshuk
2018-01-18 22:13 ` Adam Carter
2018-01-19 4:20 ` Alexander Kapshuk
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox