Extracting specific text from a file

Dear All,

I have to extract a a few lines from a log file and I know the starting String and end string(WHich is same ). Is there any simplere way using sed - awk.

e.g. from the following file
--------------------------------------
Some text
Date: 21 Oct 2008
Text to be extracted
Somemore text to be extracted
Date: 21 Oct 2008
Some more text

so I would like to extract the following lines
-------------
Text to be extracted
Somemore text to be extracted
---------------

I know the string "Date: 21 Oct 2008"

One way I can think of is do a grep -n "Date: 21 Oct 2008" filename and then user head and tail.

But I wanted to know is there any simplere way?

Regards,
Rahul

grep might help:

cat filename.txt |grep "string_in_the_file"

J.

simple grep will not help because I know the starting pattern and end pattern and I need all the text between these two patterns.

Hi,

try:

sed -n '/^start/,/^end/{/^start\|^end/!{p}}' testfile

where testfile is your file to search and start and end are the strings delimiting your pattern. This command will search every piece of text between a line starting with start and a line starting with end, inside this pattern it will print every line which doesn't start with "start" or "end".

HTH

Chris

try this one:

awk 'f==0 && /Date: 21/ {f=0; getline; f=1}
       f==1 && /Date: 21/ {f=0}f' inputfilename

One more,

awk '/Date: 21/{c=!c;next}c' file
sed -n '/Date/,/Date/p' filename | sed '/Date/d'

Hi All, ths for you replies. sed -n '/Date/,/Date/p' filename | sed '/Date/d' is giving me exact output as needed.

... another version of Christoph Spohr's solution:

sed -n '/^Date/,//{//!p;}' infile