Last active
December 18, 2015 17:49
-
-
Save TakashiUNUMA/5821630 to your computer and use it in GitHub Desktop.
Change Time by the use of date and awk command.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# | |
# change_time.sh | |
# original script coded by Takashi Unuma, Kyoto Univ. | |
# Last modified: 2013/06/21 | |
# | |
if test $# -lt 3 ; then | |
echo "USAGE: $(basename $0) [YYYYMMDDHHNN] [INT] [+/-]" | |
echo " *** Note: All values must be 'integer'. *** " | |
exit 1 | |
fi | |
# Input TIME that must be '12 digits' with the format of 'YYYYMMDDHHNN' | |
INPUTDATE=$1 | |
# time difference, unit is 'second' | |
INT=$2 | |
# flag must be '+' or '-' | |
FLAG=$3 | |
# convert from TIME to UNIXTIME | |
UTIME=$(date +%s --date "${INPUTDATE:0:4}-${INPUTDATE:4:2}-${INPUTDATE:6:2} ${INPUTDATE:8:2}:${INPUTDATE:10:2}") | |
# Output modified TIME | |
echo $(expr ${UTIME} ${FLAG} ${INT}) | awk '{print strftime("%Y%m%d%H%M",$1)}' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment