Trouble with line breaks and removing blanks

Viewed 40

I'm having trouble with preprocessing METAR(airport weather observation) data.

All my data should be like line 76~80 (each date of data in one row.), but unnecessary line breaks and blanks make this data quite useless.

For example, data in line 82 should be placed after R16 in line 81. And data in line 84 should be placed after Q1012 in line 83.

How can I deal with this problem without deleting those blanks manually?

This starts on line 76:

201903301500 METAR RKSI 301500Z 32016KT 9999 OVC030 04/M02 Q1015 NOSIG=
201903301430 METAR RKSI 301430Z 31014KT 9999 BKN030 04/M01 Q1014 NOSIG=
201903301400 METAR RKSI 301400Z 30016KT 9999 BKN025 05/M01 Q1014 NOSIG=
201903301330 METAR RKSI 301330Z 30018KT 9999 BKN030 05/M01 Q1014 NOSIG=
201903301300 METAR RKSI 301300Z 29019KT 9999 BKN030 04/M01 Q1013 NOSIG=
201903301000 METAR RKSI 301000Z 29023KT 9999 BKN030 04/M02 Q1012 WS R16
                        R34 NOSIG=
201903300930 METAR RKSI 300930Z 28020KT 9999 SCT015 BKN030 04/M01 Q1012
                        WS R16 R34 NOSIG=
1 Answers

Best is to use regular expressions, as shown in below picture enter image description here

Pattern used: \s*\n\s+

\s* matches 0+ whitespaces

\n matches newline character

\s+ matches 1+ whitespaces, so it will match newlines, with lines starting with whitespaces instead of numbers.

Found text could be replaced by a single space.

Related