Extracting formatted text and numbers

Hello,
I have a file of text and numbers from which I want to extract certain fields and write it to a new file. I would use awk but unfortunately the input data isn't always formatted into the correct columns. I am using tcsh.

For example, given the following data

I want to extract:

and print it in one line of a new file as:

and extract

and print it as:

Does anyone have any ideas as to what command I Should use?
Thanks,
Dan

Do all of the records begin
1964.01
or something similar?

Yes,
Every record that I want to extract to a new line in the output file starts with a date in the format YYYY.MM.DD. However, not all records that I want have the following lines with aang, a, and b.

Hello, DFr0st:

Your sample data in a file called data:

$ cat data
1964.01.17 121427.6 24.268s 177.074w 158.0km 4.8 Tonga 1
ep :aang= -18.5 90% : l=267.9,az= -18.5,pl=35.9
ellipse: a= 188.6 ellipsoid: l= 59.3,az= 158.6,pl=54.0
(90% ) : b= 25.2 semi-axis: l= 29.4,az=-109.5,pl= 1.4
1964.01.18 41437.6 30.000s 177.900w 48.0km 4.8 Tonga

Passing it through a tr filter to remove all characters that are not a decimal digit, decimal point, minus sign, space, or newline yields:

$ tr -cd '[-0-9. \n]' < data
1964.01.17 121427.6 24.268 177.074 158.0 4.8  1
  -18.5 90  267.9 -18.535.9
  188.6   59.3 158.654.0
90    25.2 -  29.4-109.5 1.4
1964.01.18 41437.6 30.000 177.900 48.0 4.8

Assuming that your sample data is representative of the two forms of records you mentioned, and that you did not neglect to mention any special cases, a line with 6 numbers is a single line record that only requires appending three zeros; a line with 7 numbers is the start of a multiline record and is followed by three lines of 4, 3, and 5 fields respectively (all field counts are after tr filtering). The following AWK assembles what remains into what's desired, before passing it through another tr filter to squeeze mulitple spaces into a single space:

$ tr -cd '[-0-9. \n]' < data | awk 'NF==6{print $0,0,0,0} NF==7{$2=""; $NF=""; s=$0; getline; d=$1; getline; a=$1; getline; print s,d,a,$2}' | tr -s ' '
1964.01.17 24.268 177.074 158.0 4.8 -18.5 188.6 25.2
1964.01.18 41437.6 30.000 177.900 48.0 4.8 0 0 0

Regards,
Alister