retrieved multiple lines on multiple places in a file

I have a file containing the following lines:

first line
second line
third line
something goes here
something else goes here
something goes here
first line1
second line2
third line3

I need to go through the file and retrieved these lines and print them the output should look like this:

first line
second line
third line
first line1
second line2
third line3

Please help me get start it. I used while loop but the output wasn't what I want it.

How do you know which lines you want and which you don't?

Let's say you want 3 lines, skip 3 lines, etc. Here's just one way (using GNU awk):

 awk '(int((FNR-1)/ 3))%2 == 0'  filename

Thx otheus, to answer your question, I am using `grep "^first"`, when I found it I would continue and grep for the "^second" word and so on.

Okay, so you can use "egrep" for a more interesting regular expression:

egrep "^(first|second|third) " infile.txt

if that doesn't work, just use awk with almost identical syntax:

awk "/^(first|second|third) /" infile.txt
while  read -r line
do
    case $line in
        first*|second*|third* ) echo "$line";;
    esac 
done < "file"

That looks like it should work, though like I said, the grep/awk solution would be more efficient. Maybe you should put double-quotes around the $line, as in:

case "$line" in 

In ksh and bash, you can also parse out the first word from the rest:

case "${line%% *}" in
   first|second|third) echo "$line";;
esac
while read -r a b
do
 case $a in 
  ....
 esac
done 

Right you are, ghostdog! "Doh!" to me!

Thx everyone!