scripting help

I have a file having following lines :

201110180036 METAR PABL 180036Z AUTO 13005KT 10SM SCT037 BKN045 OVC055 01/M02 A2986 RMK PNO=

201110172350 METAR ENSB 172350Z 12010KT 9999 FEW030 M010/M12 Q1008 RMK WIND 1400FT 10008KT=

201110172350 METAR ENAN 172350Z 17006KT CAVOK 06/04 Q0996=

201110172350 METAR ENDU 172350Z 00000KT 9999 FEW035 SCT090 BKN200 02/02 Q0997=

and are many more such lines. I want that it should be first read line by line and then each line word by word... and it should take only required words from each line in a new file... words are...
first it should check for the 1st word if it is date tag ie 201110172350 it should b taken,
then it shoud check for next word It should be METAR,
then the next word should be PABL or OPKC or any icao code which is of 4 letters (R) only letters.

Then the next word should be the time ie 172350Z , last 6 digits of forst word and having 'Z' in last.

Next word should be 00000KT or 23005MPS or 23005G15KT or (wind code) which can have its unit in KT or KTS or MPS or MPH....

Next word it should look for visibility, that can be 10SM or 9999 or 6000 or 5000 ( in 4 digits) or CAVOK, but if it is 10SM or CAVOK it sould be converted as 9999.

Next word it should look for the cloud layer, it can be in 3-4 wordds.... and will start either from FEW, SCT, BKN, OVC or NSC Or SKC or CAVOK.

The next word it should look for the temperature block 06/04....

the next word it should take the pressure wich will start from 'Q' eg : Q0997... or Q1002 which will be in 5digits.
And If there is any remark which wwill start from RMK it should come in last.... and each line should end with an '=' sign....

So the output of the resulting output file should be as follows:

201110180036 METAR PABL 180036Z 13005KT 9999 SCT037 BKN045 OVC055 01/M02=

201110172350 METAR ENSB 172350Z 12010KT 9999 FEW030 M010/M12 Q1008 RMK WIND 1400FT 10008KT=

201110172350 METAR ENAN 172350Z 17006KT CAVOK 06/04 Q0996=

201110172350 METAR ENDU 172350Z 00000KT 9999 FEW035 SCT090 BKN200 02/02 Q0997=
..

After this prob is solved i will tell you the next step.... i think it will be easy to break that big problem into pieces and then solve it....

Thanx in advance... .

Duplicate Post

Please continue in the other thread.

--ahamed