#!/bin/sh usage="Usage: utime2ymd [local|gmt] \n\nConvert 10-digit Unix timestamp to yyyymmdd.hhmmss format \n use local time zone (default) or UTC/GMT" [ $1 ] || { echo -e $usage; exit 1 ; } unixtime=`echo $1|cut -c -10` if [ $2 ] then qual2=`echo $2|awk '{print tolower($1)}'` if [ "$qual2" = "gmt" ] then thetime=`perl -e "print scalar(gmtime($unixtime))"` fi else qual2="local" thetime=`perl -e "print scalar(localtime($unixtime))"` fi YYYYMM=`echo $thetime | awk '{print $5 $2}' \ | sed 's/Jan/01/;s/Feb/02/;s/Mar/03/;s/Apr/04/;s/May/05/;s/Jun/06/; s/Jul/07/;s/Aug/08/;s/Sep/09/;s/Oct/10/;s/Nov/11/;s/Dec/12/'` DD=`echo $thetime | awk '{printf("%02d",$3)}'` hhmmss=`echo $thetime | awk '{print $4}' | sed 's/://g'` echo "$YYYYMM$DD.$hhmmss $qual2"