1 |
On Fri, Jan 19, 2018 at 12:13 AM, Adam Carter <adamcarter3@×××××.com> wrote: |
2 |
> On Wed, Jan 17, 2018 at 6:16 PM, Alexander Kapshuk |
3 |
> <alexander.kapshuk@×××××.com> wrote: |
4 |
>> |
5 |
>> On Wed, Jan 17, 2018 at 3:49 AM, Adam Carter <adamcarter3@×××××.com> |
6 |
>> wrote: |
7 |
>> > I'm using this to grab a section of text across multiple lines, how do i |
8 |
>> > get |
9 |
>> > it to exit after the first match? |
10 |
>> > |
11 |
>> > awk '/foo/,/bar/' |
12 |
>> |
13 |
>> See if this works for you: |
14 |
>> awk '/foo/,/bar/{print;if(/bar/)exit}' file |
15 |
>> sed '/foo/,/bar/!d;/bar/q' file |
16 |
>> |
17 |
> The awk line works. I didnt try the sed line. Thanks! |
18 |
|
19 |
Good to hear. |
20 |
Thanks for letting us know. |
21 |
|
22 |
The sed line is identical in operation to the awk one: |
23 |
(1). Delete anything that's not in the range of lines from /foo/ to /bar/; |
24 |
(2). Print the lines that match the range specified; |
25 |
(3). Quit processing further lines of input on finding the first |
26 |
occurrence of /bar/; |