Gentoo Archives: gentoo-user

From: Mike Kazantsev <mike_kazantsev@×××××××.net>
To: gentoo-user@l.g.o
Subject: Re: [gentoo-user] Grep question
Date: Mon, 02 Mar 2009 02:07:25
Message-Id: 20090302070409.2dad3992@coercion
In Reply to: [gentoo-user] Grep question by Adam Carter
1 On Mon, 2 Mar 2009 13:01:31 +1100
2 Adam Carter <Adam.Carter@×××××××××.au> wrote:
3
4 > I need to select all the lines between string1 and string2 in a file. String1 exists on an entire line by itself and string2 will be at the start of a line. What's the syntax? I cant use -A as there is a variable number of lines.
5
6 I doubt there's a solution involving grep, unless you use it twice in
7 the same pipe:
8 grep -A9999 string1 /some/file | grep -B 9999 string2
9
10 But there can be any amount of more elegant solutions, involving
11 sed:
12 sed -n '/string1/,/string2/p' /some/file
13
14 --
15 Mike Kazantsev // fraggod.net

Attachments

File name MIME type
signature.asc application/pgp-signature