Print word 1 in line 1 and word 2 in line 2 if it matches a pattern

i have a file in this pattern
MATCH1 word1 IMAGE word3 word4
MATCH2 word1 word2 word3 word4
MATCH2 word1 word2 word3 word4
MATCH2 word1 word2 word3 word4
MATCH2 word1 word2 word3 word4
MATCH1 word1 IMAGE word3 word4
MATCH2 word1 word2 word3 word4
MATCH2 word1 word2 word3 word4
MATCH2 word1 word2 word3 word4
MATCH2 word1 word2 word3 word4
MATCH1 word1 IMAGE word3 word4
now where ever i find MACTH1 in the file i need to print all the word3's in MATCH2 line till next MATCH1 appears.My o/p should look like this
IMAGE word2,word2,word2
Hope my question is clear.Please help me on this

Sounds great.

With awk...

cat file | awk '/MATCH1/||/MATCH2/ {print $3}'

Not sure that's what the OP wanted. Can the OP post a realistic sample of input and desired output files?

And anyway, you don't need cat for this: The Useless Use of cat :wink:

Rather this...

awk '{ORS=""} /MATCH1/||/MATCH2/ {print $3,","}' file

Thanks for this,But it will only Print word2 ,i i need IMAGE from MATCH1

the abv o/p will come like....

word2,word2,word2..
i need

IMAGE,word2,word2

sorry if i am not clear

The output with the command line above give this output...

IMAGE ,word2 ,word2 ,word2 ,word2 ,IMAGE ,word2 ,word2 ,word2 ,word2 ,IMAGE

nawk 'BEGIN{flag=0}{if($1=="MATCH1"){flag=!flag;printf "\n"}if(flag)printf $3" "}'