Re: Date from the time stamp



On 2006-09-28, pawan_test 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

You do not need any external program.

In any POSIX shell:

TimeStarted="${TIME%${TIME#????????}}"

With bash or ksh93:

TimeStarted=${TIME:0:8}


--
Chris F.A. Johnson, author <http://cfaj.freeshell.org/shell>
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
===== My code in this post, if any, assumes the POSIX locale
===== and is released under the GNU General Public Licence
.



Relevant Pages