[SlugBug] Re: data formatting query

Chris J cej at nightwolf.org.uk
Fri Dec 9 09:51:47 GMT 2005


And Lo! The Great Prophet " Bill Best" uttered these words of wisdom:
>>
>> 	awk '{ print $1, $2 }' < inputfile | grep -v '^$' | sort | uniq
>
> thanks - that works.  i didn't try the other methods  :o)
>

Nay probs :-)

[[ snippage date problem ]]

>
> you've anticipated my next question...
>
> any quack-ish way to get the output into date order?
>

This does the job:

    sort -t' ' -k2.5,2.6 -k2.3,2.4 -k2.1,2.2 < inputfile

This basically defines the sort keys in the format field.charpos, so we're
saying the first sort key is field 2, chars 5 and 6 (i.e., the year), so
you can probably see how the rest goes. Field 1 is the string 'Date:'. The
-t switch defines the delimiter for fields (in this case, a space). I've
tested this sort invocation so I know this bit works :-)

So plugging this in and making a minor tweak to the above to remove the
grep as we can get awk to do the job of removing the blank lines simply
enough (next three lines as one):

   awk '/^Date:/ { print $1, $2 }' < inputfile |
      sort -t' ' -k2.5,2.6 -k2.3,2.4 -k2.1,2.2 |
      uniq

Of course, this final pipeline is completely untested as usual :-) And
again, you may be able to drop the pipe to uniq by adding '-u' to sort.

Cheers,

Chris...

-- 
\ Chris Johnson                 \
 \ cej at nightwolf.org.uk          \
  \ http://cej.nightwolf.org.uk/  ~-----------------------------------+
   \ Redclaw chat - http://redclaw.org.uk - telnet redclaw.org.uk 2000 \____




More information about the SlugBug mailing list