Column transformation based on keywords in that column

Hello All,

I have raw data like below. Just 1 column .

X
1
2
3
.
.
Unknown number of rows
Y
X
1
2
.
.
Unknown number of rows
Y

where the number of rows between each matching X and Y strings are not same.
I need the following output

1 2 3
1 2

I got a awk based script( from this forums) but it is not working since the number of rows between keywords( X and Y ) are not same.
awk -v col=3 '{if(NR%col){printf "%s ",$0 }else {printf "%s\n",$0}} '
Link: How to convert a single column into several columns?
Thanks in advance..

try

 awk '/Y/{s=0}
      s{printf "%s ", $0}
      /X/{s=1}
      !s{printf "\n"}' file

Thanks pamu for your quick reply.
The code you mentioned is doing it's job put it is putting two 'Y' characters at the end of each row.
Can we get rid of that ?
Also on the actual data I have I am getting some formatting issue, I will try to work on that myself anyway.

Sidda

Try:

awk '/Y/{printf RS; f=0}f; /X/{f=1}' ORS=" " file

Change the code provided by Pamu a bit as below:

awk '/X/{s=1;next}
/Y/{s=0;print"";next}
 s{printf "%s ", $0}' file