Gentoo Archives: gentoo-user

From: Harry Putnam <reader@×××××××.com>
To: gentoo-user@l.g.o
Subject: [gentoo-user] Re: Grep question
Date: Tue, 03 Mar 2009 02:10:51
Message-Id: 87ab832w6v.fsf@newsguy.com
In Reply to: [gentoo-user] Re: Grep question by James
1 James <wireless@×××××××××××.com> writes:
2
3 > Adam Carter <Adam.Carter <at> optus.com.au> writes:
4 >
5 >
6 >> I need to select all
7 >> the lines between string1 and string2 in a file. String1 exists on
8 > an entire
9 >> line by itself and string2 will be at the start of a line. What's
10 > the syntax? I
11 >> cant use -A as there is a variable number of lines.
12 >
13 > AWK
14 >
15 > is my vote. Old, *SIMPLE* and used by most other packages when
16 > pattern matching is involved. Often AWK and SED go together..... As
17 > do Perl and AWK
18
19 Yup and using Steves' example:
20
21 $ cat a
22 abcd
23 abcd
24 abcd
25 abcd
26 abcd
27 abcd
28 abcd
29 abcd
30 abcd
31 abcd
32 abcd
33 foo <-- /foo/ true here
34 asdf
35 asdf
36 asdf
37 asdf
38 asdf
39 asdf
40 asdf
41 asdf
42 asdf
43 asdf
44 asdf
45 asdf
46 bar <-- /bar/ true here
47 fdsa
48 fdsa
49 fdsa
50
51 cat a | awk '/^foo/{FLAG=1}\
52 FLAG{print} \
53 /^bar/{FLAG=""}'
54 foo
55 asdf
56 asdf
57 asdf
58 asdf
59 asdf
60 asdf
61 asdf
62 asdf
63 asdf
64 asdf
65 asdf
66 asdf
67 bar

Replies

Subject Author
Re: [gentoo-user] Re: Grep question Etaoin Shrdlu <shrdlu@×××××××××××××.org>