small corrections, the "<" symbol is not needed, awk can read
directly from a file too.
if you want to sort it, it is easier if month is converted to
its numeric equivalent1 to 12 and print a string like:
yyyymmddhhmmss
the following script does that on a test string.
hope it helps
raymundo
#!/bin/bash
teststring="Bid End time (eBay) : Mon Feb 3 00:32:48 2003 (GMT)"
mydate=`echo $teststring | awk '{print $10,$7,$8}'`
mytime=`echo $teststring | awk '{print $9}'`
mytime=`echo $mytime | sed 's/://g'`
mydate=`echo $mydate | awk '{
month=match("JanFebMarAprJunJulAgoSepOctNovDec",$2)
month=(month+2)/3
printf("%4d%2.2d%2.2d", $1, month, $3)
}'`
echo "$mydate$mytime"
Hugh E Cruickshank wrote:
Hi Ryan:
I believe I have some link at the office. I will try and remember
to forward them to you on Monday.
In the interim, take a look at the awk command. This will allow
you to reformat the input lines (as well as many other things).
For a start the command:
awk '{print $10 " " $7 " " $8 " " $9}' <infile
(where infile is you input file name) will reformat your line to:
2003 Feb 3 00:32:48
You can then pipe the output to sort to sort the lines.
Perl would probably be better but I don't know it well enough to
give you an example. Anyway, that should give you a push in the
right direction.
There is a newsgroup, comp.unix.shell, that might be a better
place to post shell programming questions.
HTH
Regards, Hugh
--
Hugh E Cruickshank, Forward Software, www.forward-software.com
From: RD Egeland Sent: Saturday, February 01, 2003 16:51
I'm just learning how to write shell scripts, and I'd like to
find example
scripts to look at. The BASH howto and Advanced BASH howto isn't
too great
in this respect.
The immediate task I'm trying to do is extract a date into a standardized
format which I can then somehow sort. The text I need to extract
the date
from looks like:
Bid End time (eBay) : Mon Feb 3 00:32:48 2003 (GMT)
Any tips?
Ryan
--
redhat-list mailing list
unsubscribe mailto:[EMAIL PROTECTED]?subject=unsubscribe
https://listman.redhat.com/mailman/listinfo/redhat-list