Adam Carter wrote:
> 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.
Perl will handle this easily enough for you.
Assuming you want to print string1 and string2:
perl -n -e 'print if /string1/ ../string2/';
The '..' notation behaves sort of like a triac
(flip-flop?): it is false until the first test
is true and true until the second passes, at
which point it stays false again.
for example:
$ cat a
abcd
abcd
abcd
abcd
abcd
abcd
abcd
abcd
abcd
abcd
abcd
foo <-- /foo/ true here
asdf
asdf
asdf
asdf
asdf
asdf
asdf
asdf
asdf
asdf
asdf
asdf
bar <-- /bar/ true here
fdsa
fdsa
fdsa
$ perl -n -e 'print if /foo/ .. /bar/';
foo
asdf
asdf
asdf
asdf
asdf
asdf
asdf
asdf
asdf
asdf
asdf
asdf
bar
--
Steven Lembark 85-09 90th St.
Workhorse Computing Woodhaven, NY, 11421
[email protected] +1 888 359 3508