how to parse this file in unix

Hi all,
I need to parse a file which is having this format:

Details: 1
Name{
first=james
second=steven
}
Sibling{
first=2
second=3
}
Age{
first=13
second=14
}
Friend{
jessy
}
Details: 2
Name{
first=lily
second=tracy
}
Sibling{
first=2
second=3
}
Age{
first=13
second=14
}
Hobby{
hobby1=swimming
}
The output is
Name_first,Name_second,Sibling_first,Sibling_second,Age_first,Age_second,Friend,Hobby1
james,steven,2,3,13,14,jessy,
lily,tracy,2,3,13,13,,swimming

At first, I hardcode the header and use awk to retrieve the value line by line. e.g:
A=`awk 'NR==3 {
for(i=1;i<=NF;i++){
if ( $i == "first" ) {
print $3 $4
}
}
}' file`

However, the details: 1 and and details: 2 is different.Any idea on how to parse this file? Need it urgently. Thanks for help!

awk-syntax, something like:

BEGIN { FS="=" 
           object=""
           print "Name_first,Name_second,Sibling_first,Sibling_second,Age_first,Age_second,Friend,Hobby1"
           OFS=","   # print use this delimeter, if you have comma between arguments in print command
           }

/^Detail/ { # start new record, print out previous
                print Name_first,Name_second,...
                # init variables
                Name_first=""
                Name_second=""
                ...
             }
/^Age/ { object="age" ; continue }
/^Name/ { object="name" ; continue }
...
/^first/ { if (object == "age" ) { Age_first=$2 ; continue } 
             if (object == "name" ) { Name_first=$2 ; continue } 
             ...
           }
/^second/ { # like first
           }

END  {  # last record out
           print Name_first,Name_second,...
       }

hi kshji,

I am a newbie in unix and also awk syntax.
Can you explain in more detail? e.g: I do not understand
END { # last record out
print ....
}

Thanks again for your help

When you have Detail line, previous record end => print variables.
After last record you have not Detail line, so after everything END block you must print last record variables.

Hi kshji,

I have try the code,

but the output is
Details 1:

Nothing is display after Details 1.

thanks.

Hi kshji,

Good Script... I just got an interest to learn awk scripting. Can you please post any URL or PDF related awk, which would help me..

I can't see your code ? How did you try it to use ? My code was only "proto", idea of parsing input and make output. Learning awk, not only cut&paste. Giving idea of scripting, in this case using awk. I think that in this forum we are waiting that you have basic knowledge from tool what you are using/asking helps.

Subject is "how to parse this file in unix", better subject is
"how to parse this file using awk", if you like to know/learn solution using awk.
Good subject help me( us ) to browse all subject and which are maybe for just for me. Too generally subjects make this "hoppy" hard - too much noice.

Awk basic:
Part 1
Part II
Part III

Thanks kshji

hi kshji,

I know what is wrong with my code because of {Age_first=$3; continue}.May I know why the code should like this

{ Age_first=$2; continue } and is not {Age_first=$3; continue} ? Since the value is in column 3.

thanks.