How to print the lines between the two lines?

Hi friends,
Please help me in this...

lets say in the below program

...........
...........

Start
"Hello"
"welcome to this world"
END
...................
...................
Start
"Hi"
"Welcome to C Program"
END
...................
...................

In this how to print the lines between Start and END?

Try this,

sed -n '/Start/,/END/p' <inputfilename>

If you don't want the delimiting lines to be printed, you can do something like that :

awk '/Start/ { ok=1 } /END/ { ok=0 } ok' inputfile

Jean-Pierre.

Guess aigles wanted something like this..

awk '/Start/ {getline; ok=1 } /END/ { ok=0 } ok' inputfile

Opps, thanks michaelrozar17

Another version that doesn't needs a getline :

nawk '/END/ { ok=0 } ok ; /Start/ { ok=1 }' inputfile

Jean-Pierre.

 
perl -0ne 'print $1 if /Start(.*)END/sg' input

The sed solution, as mentioned above, prints out the delimiting lines. Both the sed and awk solutions will start printing lines as soon as they see a line matching "Start"; they will not wait until the matching "END" is found. This could be relevant if one wants to strictly limit output to sections bounded on both ends by the respective patterns.

In case it's of any use, here's a sed solution that does not print the delimiting lines and that insures that the tail of any printed text is /END/ delimited:

sed -n '/^START$/,/^END$/{/^END$/{s/.*//; x; s/\nSTART\n//p; d;}; H;}'

Regards,
Alister

---------- Post updated at 12:00 PM ---------- Previous update was at 11:49 AM ----------

Hi, getmmg:

Using the following sample data, for me your suggestion yields nothing (0 bytes of output). Is there something in that one-liner that may not be supported in perl 5.8.6 (it's an old OS X Tiger 10.4.11 machine)? I skimmed over a couple of the perldelta pods for later releases, but nothing jumped out at me.

My sample data:

START
yes1
yes2
END
no
START
END
START
yes3
yes4
yes5
END
no
no
START
no
no

Expected output:

yes1
yes2
yes3
yes4
yes5

It's not important, but I'm curious to know. Any ideas?

Disclaimer: When I last regularly hacked with perl, references were new! :wink:

Regards,
Alister

A variation of alister's sed solution with awk (and with a more ugly sample data file) :

awk '/START/ { m=""; ok=1; next } /END/ && ok { if (m) printf "%s", m; ok=0  } ok { m=m $0 "\n" }' data.txt

Sample data file

no
END
no
START
yes1
yes2
END
no
START
END
START
no
START
yes3
yes4
yes5
END
no
no
START
no
no

Output:

yes1
yes2
yes3
yes4
yes5

Jean-Pierre.

Hi Friends,

Thanks to all of u for ur spontaneous replies.... 

A small requirement added in my query is that...

A file is undergoing changes phase by phase...so I will comment the changes of respective phase as below

..............
..............

/* Start: Phase1/001 */
Hi
Hello
Yes
No
/* End: Phase1/001 */
...........
...........
...........
/* Start: Phase1/002 */
Yes
No
World
/* End: Phase1/002 */
.........
.........
/* Start: Phase2/001*/
Boys
Girls
Parents
Child
/* End: Phase2/001 */
.......
......

Now If I input the values of phase no(1,2,3...) and the modification no.(001/002/003....) in the respective phase, I have to get the output for those respective phase changes...

For Eg: If I input Phase:1 and modification no:2, I have to get the output as

/* Start: Phase1/002 */
Yes
No
World
/* End: Phase1/002 */

---------- Post updated 06-30-11 at 11:24 AM ---------- Previous update was 06-29-11 at 06:54 PM ----------

Hi Friends...plz do help me

Try something like that :

phase=1
mod=002
awk -v pm="$phase/$mod" '
BEGIN {
    Start = "^/\\* Start: Phase" pm;
    End   = "^/\\* End: Phase" pm;
}
$0 ~ Start,$0 ~ End
' inputfile

jean-Pierre.