jisha
1
HI,
I have a script where the date and time has to e printed separately as below
date = "Wed Jan 16 2008"
time = "14:17:57 IST"
using date command gives me tho out put
Wed Jan 16 14:17:57 IST 2008
i need only Wed Jan 16 2008 and 14:17:57 IST both stored in two different variables.
How is this possible?
Thanks in advance
JS
Hi,
either you do seperate and format it with "%" like for hours only:
date +%hh
or you use awk
date | awk '{ print $1 $2 $3 $5 }'
WedJan16GMT
date | awk '{ print $4 }'
09:09:17
Gruss
Andi
check with man date or info date
A simply way executing date once:
> date|read d m D h z y
> date="$d $m $D $y"
> time="$h $z"
heyjoe
4
Use the date command, but specify a format by using the + option.
$ date "+%a %b %d %Y"
Wed Jan 16 2008
$ date '+%H:%M:%S %Z'
09:16:04 GMT
Look on the Web for more info - eg Date (Unix - Wikipedia, the free encyclopedia)
Or type "man date" on a UNIX terminal.
# date +"%a %b %d %Y"
Wed Jan 16 2008
you can do the rest for time, check the man page
jisha
6
Thanks a lot
I Found the answer
I used :
today="`date +%D`"
awk ' BEGIN {printf("%105s","'"${today}"'")} ' >>report.txt
time="`date +"%r"`"
awk ' BEGIN {printf("%116s","'"${time}"'")} ' >>report.txt
# printf "%105s" `date +%D`
ilan
8
Hi jisha,
as per your given data above... you can do like this
curr=Wed Jan 16 2008 14:17:57 IST
date1=`echo $curr | cut -c 1-15`
time1=`echo $curr | cut -c 17-28`
-ilan