Re: [gentoo-user] Grep question
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 Lembark85-09 90th St. Workhorse Computing Woodhaven, NY, 11421 lemb...@wrkhors.com +1 888 359 3508
Re: [gentoo-user] Grep question
On Mon, 2 Mar 2009 13:01:31 +1100 Adam Carter adam.car...@optus.com.au 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. I doubt there's a solution involving grep, unless you use it twice in the same pipe: grep -A string1 /some/file | grep -B string2 But there can be any amount of more elegant solutions, involving sed: sed -n '/string1/,/string2/p' /some/file -- Mike Kazantsev // fraggod.net signature.asc Description: PGP signature