Prev: Possible to define a variable for only certain directories?
Next: starfield in Bash for GNU/Linux
From: Michael Paoli on 27 Nov 2009 22:48 On Nov 18, 3:14 pm, "#! /shell/nerd" <vikasera(a)gmail.com> wrote: > sed '/AAA/,/BBB/p' <file> gives me > AAA > some text > some text > BBB Now, that would seem to be a rather interesting trick without the -n option to sed(1), as the default action is p, and an explicit p would then double that output, e.g.: $ echo 'AAA > some text > some text > BBB' | > sed '/AAA/,/BBB/p' AAA AAA some text some text some text some text BBB BBB > Now I want is the out put without AAA or BBB. How is this possible > with a single sed command? I tried following but didn't work - > sed '/AAA/,/BBB/{ 1d; $d; p; }' <file> So, let's presume you meant something more like: sed -ne '/AAA/,/BBB/p' <file> gave you: AAA some text some text BBB and want similar, but without the starting AAA and ending BBB lines. sed -ne '/AAA/,/BBB/{;/AAA/n;:l;/BBB/d;p;n;bl;}'
From: w_a_x_man on 27 Nov 2009 23:46 On Nov 18, 5:14 pm, "#! /shell/nerd" <vikas...(a)gmail.com> wrote: > HI, > > sed '/AAA/,/BBB/p' <file> gives me > > AAA > some text > some text > BBB > > Now I want is the out put without AAA or BBB. How is this possible > with a single sed command? I tried following but didn't work - > sed '/AAA/,/BBB/{ 1d; $d; p; }' <file> ruby -ne'BEGIN{$a=[]};$a << $_ if ~/AAA/ .. ~/BBB/;END{puts $a [1..-2]}' file
First
|
Prev
|
Pages: 1 2 3 4 Prev: Possible to define a variable for only certain directories? Next: starfield in Bash for GNU/Linux |