Apologies but this question comes from a question previously raised: How can I convert a local date-time into UTC date-time? Toby has been absolutely great helping me with some conversion string-->BST -->GMT but ow i am facing another i believe dummy issue.
my .sh is simple:
# variables needed for testing
DateNew="20150903"
TimeNew="200001"
# concatenating date and time
DateTimeNew_Suffix=${DateNew}${TimeNew}
# storing the conversion provided by Toby Speight into a variable
newPrefix=`echo "${DateTimeNew_Suffix}"| sed -re 's/^([0-9]{8})([0-9]{2})([0-9]{2})([0-9]{2})$/\1\\ \2:\3:\4/'| xargs date +@%s -d | xargs date -u +%Y%m%d%H%M%S -d`
#printing that value
echo $newPrefix
expected would be: "20150903190001" which should be the value assigned as a String into $newPrefix however Unix itself is throwing this exception:
date: extra operand
20:00:01' Try
date --help' for more information.date: option requires an argument -- 'd' Try `date --help' for more
information.
Running the command on its own i get the output expected:
echo "20150903200001" | sed -re 's/^([0-9]{8})([0-9]{2})([0-9]{2})([0-9]{2})$/\1\\ \2:\3:\4/' | xargs date +@%s -d | xargs date -u +%Y%m%d%H%M%S -d
20150903190001
how can I store this echo into the newPrefix variable as a string? it look like conversion date into the variable is failing but the echo is not.
any help?