From: #! /shell/nerd on
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>
From: Chris F.A. Johnson on
On 2009-11-18, #! /shell/nerd 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>

sed -e '1,/AAA/d' -e '/BBB/,$d'

--
Chris F.A. Johnson, author <http://shell.cfajohnson,com/>
===================================================================
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
Pro Bash Programming: Scripting the GNU/Linux Shell (2009, Apress)
===== My code in this post, if any, assumes the POSIX locale =====
===== and is released under the GNU General Public Licence =====
From: Janis Papanagnou on
#! /shell/nerd 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>

Mind using awk?

awk '/BBB/{f=0};f;/AAA/{f=1}'


Janis
From: #! /shell/nerd on
On Nov 18, 5:25 pm, "Chris F.A. Johnson" <cfajohn...(a)gmail.com> wrote:
> On 2009-11-18, #! /shell/nerd 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>
>
> sed -e '1,/AAA/d' -e '/BBB/,$d'
>
> --
>    Chris F.A. Johnson, author       <http://shell.cfajohnson,com/>
>    ===================================================================
>    Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
>    Pro Bash Programming: Scripting the GNU/Linux Shell (2009, Apress)
>    ===== My code in this post, if any, assumes the POSIX locale  =====
>    ===== and is released under the GNU General Public Licence    =====

Following is the output of sed command I used & not the file content -
AAA
some text
some text
BBB
The file contains so many other blocks too. So the command you gave
doesn't help. It would remove the first & last line from the file &
not from this filtered block. Correct me if I'm wrong.
From: #! /shell/nerd on
On Nov 18, 5:25 pm, Janis Papanagnou <janis_papanag...(a)hotmail.com>
wrote:
> #! /shell/nerd 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>
>
> Mind using awk?
>
>    awk '/BBB/{f=0};f;/AAA/{f=1}'
>
> Janis

It works. Please explain it to me. I'm not so good with awk. Also I
find the Second regex is used first. Why is this order important.