For Programmers: Free Programming Magazines  


Home > Archive > Unix Programming > September 2006 > getting date from timestamp









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author getting date from timestamp
pawan_test

2006-09-28, 7:00 pm

Hi All,

i have a time stamp. from that i am trying to awk to get the year,
month and date.

TIME=20060614092446

DESIRED OUTPUT: 20060614

i am doing the following;

TIME=20060614092446
$ TimeStarted=`expr match '$TIME' '.*\(......\)'`
echo $TimeStarted

i am not getting any output. can anyone please suggest me.

thanks
mark

Barry Margolin

2006-09-28, 7:00 pm

In article <1159458333.353715.103030@k70g2000cwa.googlegroups.com>,
"pawan_test" <sridhara007@gmail.com> wrote:

> Hi All,
>
> i have a time stamp. from that i am trying to awk to get the year,
> month and date.
>
> TIME=20060614092446
>
> DESIRED OUTPUT: 20060614
>
> i am doing the following;
>
> TIME=20060614092446
> $ TimeStarted=`expr match '$TIME' '.*\(......\)'`
> echo $TimeStarted
>
> i am not getting any output. can anyone please suggest me.


Single quotes prevent variable expansion, use double quotes.

Also, your regular expression is incorrect, it should be '^\(........\)'
to get the first 8 characters -- your expression will grab the last 6
characters.

You can also do this without regular expressions at all, just shell
variable substring syntax:

TimeStarted=${TIME:0:8}

--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com