1 |
Adam Carter wrote: |
2 |
> I need to select all the lines between string1 and string2 in a file. |
3 |
> String1 exists on an entire line by itself and string2 will be at the |
4 |
> start of a line. What's the syntax? I cant use -A as there is a variable |
5 |
> number of lines. |
6 |
|
7 |
Perl will handle this easily enough for you. |
8 |
|
9 |
Assuming you want to print string1 and string2: |
10 |
|
11 |
perl -n -e 'print if /string1/ ../string2/'; |
12 |
|
13 |
The '..' notation behaves sort of like a triac |
14 |
(flip-flop?): it is false until the first test |
15 |
is true and true until the second passes, at |
16 |
which point it stays false again. |
17 |
|
18 |
for example: |
19 |
|
20 |
$ cat a |
21 |
abcd |
22 |
abcd |
23 |
abcd |
24 |
abcd |
25 |
abcd |
26 |
abcd |
27 |
abcd |
28 |
abcd |
29 |
abcd |
30 |
abcd |
31 |
abcd |
32 |
foo <-- /foo/ true here |
33 |
asdf |
34 |
asdf |
35 |
asdf |
36 |
asdf |
37 |
asdf |
38 |
asdf |
39 |
asdf |
40 |
asdf |
41 |
asdf |
42 |
asdf |
43 |
asdf |
44 |
asdf |
45 |
bar <-- /bar/ true here |
46 |
fdsa |
47 |
fdsa |
48 |
fdsa |
49 |
|
50 |
$ perl -n -e 'print if /foo/ .. /bar/'; |
51 |
foo |
52 |
asdf |
53 |
asdf |
54 |
asdf |
55 |
asdf |
56 |
asdf |
57 |
asdf |
58 |
asdf |
59 |
asdf |
60 |
asdf |
61 |
asdf |
62 |
asdf |
63 |
asdf |
64 |
bar |
65 |
|
66 |
|
67 |
-- |
68 |
Steven Lembark 85-09 90th St. |
69 |
Workhorse Computing Woodhaven, NY, 11421 |
70 |
lembark@×××××××.com +1 888 359 3508 |