http://stackoverflow.com/questions/6508819/convert-date-formats-in-bash
#since this was yesterday
date -dyesterday +%Y%m%d
#more precise, and more reccomended
date -d'27 JUN 2011' +%Y%m%d
#assuming this is similiar to yesterdays `date` question from you
#http://stackoverflow.com/q/6497525/638649
date -d'last-monday' +%Y%m%d
#going on @seth's comment you could do this
DATE = "27 jun 2011"; date -d"$DATE" +%Y%m%d
#or a method to read it from stdin
read -p " Get date >> " DATE; printf " AS YYYYMMDD format >> %s" `date
-d"$DATE" +%Y%m%d`
#which then outputs the following:
#Get date >> 27 june 2011
#AS YYYYMMDD format >> 20110627
#if you really want to use awk
echo "27 june 2011" | awk '{print "date -d\""$1FS$2FS$3"\" +%Y%m%d"}' | bash
#note | bash just redirects awks output to the shell to be executed
#FS is field separator, in this case you can use $0 to print the line
#But this is useful if you have more than one date on a line
#since this was yesterday
date -dyesterday +%Y%m%d
#more precise, and more reccomended
date -d'27 JUN 2011' +%Y%m%d
#assuming this is similiar to yesterdays `date` question from you
#http://stackoverflow.com/q/6497525/638649
date -d'last-monday' +%Y%m%d
#going on @seth's comment you could do this
DATE = "27 jun 2011"; date -d"$DATE" +%Y%m%d
#or a method to read it from stdin
read -p " Get date >> " DATE; printf " AS YYYYMMDD format >> %s" `date
-d"$DATE" +%Y%m%d`
#which then outputs the following:
#Get date >> 27 june 2011
#AS YYYYMMDD format >> 20110627
#if you really want to use awk
echo "27 june 2011" | awk '{print "date -d\""$1FS$2FS$3"\" +%Y%m%d"}' | bash
#note | bash just redirects awks output to the shell to be executed
#FS is field separator, in this case you can use $0 to print the line
#But this is useful if you have more than one date on a line
'Linux' 카테고리의 다른 글
osx 내 git branch name 얻기 (0) | 2015.05.26 |
---|---|
bash date (0) | 2015.04.28 |
Recursively delete .svn directories (0) | 2015.04.07 |
Prepend current git branch in terminal (0) | 2015.01.15 |
synergy (0) | 2014.08.19 |