String replacement

Hi,

I have a text file where all records come in one line (single line file), each record starts with 'BUCH' and ends with '@&' and if data is not there we get space instead. between '@&' and next record there might be some spaces, now I want to remove those spaces between '@&' and 'BUCH'.

Please help.

Input file

BUCH20131013                                                          4748420001                    BUCA20131013                                                          4748520001                    '@&'               BUCH20131013                                                          4748420002                    BUCA20131013                                                          4748520002                    '@&'               BUCH20131013                                                          4748420001                    BUCA20131013                                                          4748520003                    '@&'               BUCH20131013                                                          4748420001                    BUCA20131013                                                          4748520004                    '@&'               BUCH20131013                                                          4748420001                    BUCA20131013                                                          4748520005                   

output:

BUCH20131013                                                          4748420001                    BUCA20131013                                                          4748520001                    BUCH20131013                                                          4748420002                    BUCA20131013                                                          4748520002                    BUCH20131013                                                          4748420001                    BUCA20131013                                                          4748520003                    BUCH20131013                                                          4748420001                    BUCA20131013                                                          4748520004                    BUCH20131013                                                          4748420001                    BUCA20131013                                                          4748520005                   

Thanks in advance.

Some like this:

awk "{gsub(/ '\@\&'/,x)}1" file
BUCH20131013 4748420001 BUCA20131013 4748520001 BUCH20131013 4748420002 BUCA20131013 4748520002 BUCH20131013 4748420001 BUCA20131013 4748520003 BUCH20131013 4748420001 BUCA20131013 4748520004 BUCH20131013 4748420001 BUCA20131013 4748520005

PS remember Code Tags

Try:

sed "s/ *'@&' */ /g" file

Using sed

sed "s/ '@&' /\n/g" infile 
BUCH20131013 4748420001 BUCA20131013 4748520001
BUCH20131013 4748420002 BUCA20131013 4748520002
BUCH20131013 4748420001 BUCA20131013 4748520003
BUCH20131013 4748420001 BUCA20131013 4748520004
BUCH20131013 4748420001 BUCA20131013 4748520005

To avoid line length limitations one could try breaking it down in actual records.

gawk '{sub($NF,x)}1' RS=BUCH ORS=BUCH file