If I have the following string:
1234-56-78 17:38:00,00 [main]
and I want to isolate the second 'word',
17:38:00,00
and then parse this word (clearly a time stamp) to isolate each the 17 and the 38 and put them out to variables, how can I do this? I've tried the following, in getting the hour:
stampLine="1234-56-78 17:38:00,00 [main]"
array=("$stampLine")
fullStamp=${array[1]}
IFS=':' read -ra splitStamp <<< $fullStamp
stampArray=($splitStamp)
x=${stampArray[0]}
echo ${x#0} # to strip leading zeroes
as well as:
declare -i index
for item in $array; do
if [ index == 1 ]; then
fullStamp=$item
IFS=':' read -ra splitStamp <<< $fullStamp
stampArray=($splitStamp)
x=${stampArray[0]}
echo ${x#0} # to strip leading zeroes
fi
done
but both of them have failed, which brings me here. If someone could answer this and/or explain what I'm missing, I would much appreciate it.