Print Nth to last field

Hey,

I'm sure this is answered somewhere but my Googling has turned up nothing. I have a file with data in the following format:

<desription of event> at <time and date>

The desription of the event is variable length and hence when the list is displayed it is hard to easily see the date (and it looks messy). To resolve this, I would like to print the information with the time and date first followed by the description and just ditch the word at. For example:

Layout in file:

Eat some pies at Thu Oct 11 03:52:30 GMT 2012
Got stuck on this code at Thu Oct 11 04:51:30 GMT 2012
Eat many more pies at Thu Oct 11 05:52:30 GMT 2012

desired printed output:

Thu Oct 11 03:52:30 GMT 2012 Eat some pies
Thu Oct 11 04:51:30 GMT 2012 Got stuck on this code
Thu Oct 11 05:52:30 GMT 2012 Eat many more pies

I can do this easily using awk when I know the length of each line but I don't.

Is there a way to get awk to count from the end rather than the start as the date will always be the same length?

Alternatively is there a way to switch the text either side of "at" as I don't think "at" will ever appear in any of the real descriptions?

If anyone can help, it would be really appreciated.

Thanks

awk 'match($0, " at *" $(NF-5)){print substr($0, RSTART+4) substr($0,1, RSTART)}' myFile

Perl:

perl -lpe 's/(.*) at (.*)/$2 $1/' file

bartus11: Thanks, but we're not meant to use perl in our scripts - I don't know why it's just part of the standards (I should have mentioned that before.

vgersh99: That syntax errors ("near line 1"), I'm trying to work from your suggestion at the moment though.

A couple of other things I should have mentioned before:

1: The script is in ksh and it has to work on both Linux and Solaris.
2: I do not have multiple lines in one file but multiple files each containing only one line. I don't know if that makes a difference.

Thanks for the suggestions so far.

use 'nawk' instead of 'awk' on Solaris

sed?

sed '/ at /s/\(.*\) at \(.*\)/\2 \1/' infile

Dude that is perfect! Thanks so so much.

Here are two other ways to do this using awk (nawk or /usr/xpg4/bin/awk on Solaris systems):

# Use this if " at " doesn't appear anywhere else in the input file(s).
awk -F " at " '{print $2,$1}' file

# Use this if " at " can appear somewhere else in the input file(s).
awk '{for(i=NF-5;i<=NF;i++)printf("%s ",$i)
      for(i=1;i<=NF-7;i++) printf("%s%s",$i,i<NF-7?" ":"\n")
}' file

sed and perl work nicely in the case of multiple " at "'s because of greedy matching. Alternative awk:

awk -F' at ' '{p=$NF; gsub(FS p,x); print p,$0}' file