olav Apr 10, 2012 #1 I have this string: Code: 2012-04-10_08-00 How can I parse this to year, month and day? Why wouldn't something like this work? Code: read Y M D h m s <<< ${timestamp//[-_]/ }
I have this string: Code: 2012-04-10_08-00 How can I parse this to year, month and day? Why wouldn't something like this work? Code: read Y M D h m s <<< ${timestamp//[-_]/ }
UNIXgod Apr 10, 2012 #2 <<< is a bashism. you could translate the hyphen to a newline and loop it in to variables if you need them or just send them to their respective output: Code: % echo "2012-04-10_08-00" | tr '_-' '\n' 2012 04 10 08 00
<<< is a bashism. you could translate the hyphen to a newline and loop it in to variables if you need them or just send them to their respective output: Code: % echo "2012-04-10_08-00" | tr '_-' '\n' 2012 04 10 08 00
S Shamrock Apr 10, 2012 #3 Code: > cat test.sh #!/bin/sh test=`echo '2012-04-10_08-00' | tr '_-' ' '` set $(echo $test); echo $1 Code: > ./test.sh 2012
Code: > cat test.sh #!/bin/sh test=`echo '2012-04-10_08-00' | tr '_-' ' '` set $(echo $test); echo $1 Code: > ./test.sh 2012
V varda Apr 10, 2012 #4 Code: # date -f "%Y-%m-%d_%H-%M" 2012-04-10_08-00 "+%Y" 2012 # date -f "%Y-%m-%d_%H-%M" 2012-04-10_08-00 "+%B" April DATE="2012-04-10_08-00"; MONTH=$(date -f "%Y-%m-%d_%H-%M" $DATE "+%B")
Code: # date -f "%Y-%m-%d_%H-%M" 2012-04-10_08-00 "+%Y" 2012 # date -f "%Y-%m-%d_%H-%M" 2012-04-10_08-00 "+%B" April DATE="2012-04-10_08-00"; MONTH=$(date -f "%Y-%m-%d_%H-%M" $DATE "+%B")