Combining chunks of data

Hi there! Need help on some issue, I have data like this:

123
456

789
012

i need it to be like this:

123789
456012

Anyone has any idea how to do this? Thanks!

Regards,
Ken

Use code tags as Franklin52 stated in his moderator notice in your post, thanks.

It could be written easier maybe, but works for this example:

$ awk '{a[NR]=$1; b[NR]=$2} END{for(x=1; x<=NF; x++){s1?s1=s1""a[x]:s1=a[x]; s2?s2=s2""b[x]:s2=b[x]}; print s1 ORS s2}' FS="\n" RS="\n\n" infile
123789
456012

Thanks!

If I have more than 2 chunk then does it mean that I'll have to add on to the command? Thanks again!

The code I have given is not very generic. Do you mean more than 2 chunks like this:

aaa
bbb

ccc
ddd

eee
fff
...

... or like this:

aaa
bbb
ccc
ddd

eee
ffff
ggg
hhh

?

For the 1st example it should still work. You can simply try it out.

You can give this a try:

awk '!NF{c=0;next} {a[c++]=a[c] $0} END{for(i in a) print a}' file
awk 'BEGIN{f=1;i=1}{if(length($0)==0){f=0;k=1;next};if(f==1){a=$1;i++}else{if(f==0&&k<i){print a[k],$1;k++}else{f=1;i=1}}}' inputfile

Not that easy. Check the required output again.

sorry for interpreting output wrongly try this

awk 'BEGIN{f=1;i=1}{if(length($0)==0){f=0;k=1;next};if(f==1){a=$1;i++}else{if(f==0&&k<i){print a[k],$1;k++}else{f=1;i=1}}}' inputfile
awk '{
n=split($0,b,RS)
for(i=1;i<=n;i++)
 a=a?ab:b
}
END {
for(i=1;a;i++)
 print a
}' RS= infile