This is not a homework assignment. I am new to bash and trying to gather some data from our logging.
I am reading lines from a file. All of the lines look like this:
[info] 1 - 12-04 15:33:37.542 : Finished createWalletRandom, total time 9898ms
I need to parse out the milliseconds (which I will get min, max, average). I can get 9898ms
and I need to get rid of the ms
for the math to work.
Trying this line below, doesn't change anything:
MILLI_SECONDS=${RAW_MILLI_SECONDS%??}
And trying this below, generates an error get_wallet_times.sh: line 23: -2: substring expression < 0
:
MILLI_SECONDS=${RAW_MILLI_SECONDS::-2}
Here is my code:
while read ONE_LINE;
do
echo $ONE_LINE
RAW_MILLI_SECONDS="$(cut -d' ' -f13 <<<"$ONE_LINE")"
echo $RAW_MILLI_SECONDS
MILLI_SECONDS=${RAW_MILLI_SECONDS::-2}
MILLI_SECONDS=${RAW_MILLI_SECONDS%??}
echo ${MILLI_SECONDS}
LINE_COUNT=$((LINE_COUNT+1))
FILE_SUM=$((FILE_SUM+MILLI_SECONDS))
done < logfile.txt
This is on macOS, in case its a bash issue specific to mac. Please let me know if there is anything thing else you need.
Thnx Matt
MILLI_SECONDS=${RAW_MILLI_SECONDS/ms/}
work?ms
so%??
removes two of them. What is the output ofecho "${RAW_MILLI_SECONDS}X"
?echo "|${RAW_MILLI_SECONDS}|"
and got back|9898ms|
. So I don't think theres anything trailing, unless I did that wrong.