Merging lines

Hi folks.

Could somebody help me write a script or command that will look through a file and for every line that doesn't contain a certain value, merge it with the one above?

For example, the file contains:
SCOTLAND|123|ABC|yes
SCOTLAND|456|DEF|yes
SCOTLAND|78
9|GHI|yes
SCOTLAND|101|JKL|yes
SCOTLA
ND|112|M
NO|yes
SCOTLAND|131|PQR|yes
SCOTLAND|415|STU|yes
SCOTLAND|161|VWX|yes

I need to have all the lines merged so each line starts with SCOTLAND:

SCOTLAND|123|ABC|yes
SCOTLAND|456|DEF|yes
SCOTLAND|789|GHI|yes
SCOTLAND|101|JKL|yes
SCOTLAND|112|MNO|yes
SCOTLAND|131|PQR|yes
SCOTLAND|415|STU|yes
SCOTLAND|161|VWX|yes

Is this possible?

The file I receive has ^M at the end of each records 'yes' value, but for some reason the lines are splitting up - could this be 'line feeds'?

Did you try dos2unix?

After you converted to unix format, try this:

awk -F\| '{while(NF<4&&getline n)$0=$0n}1' infile

All sorted guys, using a combination of dos2unix and perl!

Thanks for your help and suggestions.:b: