The following script:
DYN_HOSTS_START_ARRAY=($(grep -E "STARTING HOST" sample.log | cut -d' ' -f 1,2))
for ((i=0; i< ${#DYN_HOSTS_START_ARRAY[@]}; i++))
do
echo "$i: start: "${DYN_HOSTS_START_ARRAY[$i]}""
done
Using the following sample.log file:
2019-11-11 19:05:55,823 DEBUG STARTING HOST 46
2019-11-11 19:05:55,831 DEBUG STARTING HOST 703
2019-11-11 19:05:55,837 DEBUG STARTING HOST 505
2019-11-11 19:05:55,858 DEBUG STARTING HOST 93
2019-11-11 19:05:55,859 DEBUG STARTING HOST 486
2019-11-11 19:05:55,861 DEBUG STARTING HOST 72
2019-11-11 19:05:55,879 DEBUG STARTING HOST 855
2019-11-11 19:05:55,913 DEBUG STARTING HOST 560
2019-11-11 19:05:56,067 DEBUG STARTING HOST 199
Yields the following undesired output:
0: start: 2019-11-11
1: start: 19:05:55,823
2: start: 2019-11-11
3: start: 19:05:55,831
4: start: 2019-11-11
5: start: 19:05:55,837
6: start: 2019-11-11
7: start: 19:05:55,858
8: start: 2019-11-11
9: start: 19:05:55,859
10: start: 2019-11-11
11: start: 19:05:55,861
12: start: 2019-11-11
13: start: 19:05:55,879
14: start: 2019-11-11
15: start: 19:05:55,913
16: start: 2019-11-11
17: start: 19:05:56,067
The desired output should only have 9 elements (instead of 18), each element containing both the date and the time, separated by the original space.
How do I fix my script, while retaining the array initialization, to 9 elements only, to accomplish that?