...........
...........
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?
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!
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 ----------