Using multi-factor separator in bash script

I have a text file in which the data has the form:

Number of Iterations: 150
Average time is 45 ms
Average time for collisions is 50 ms
Total time is 95 ms
....

There are several files of this type. I have to read all these files and create a csv file that will contain the form entries:

150,45,50,95
200,40,60,100 
...
...

where each line corresponds to one txt file.
I am writing a bash script to generate a CSV file from this data.
I want to read only the numbers from a text file.
For the first line, I tried to use

    IFS =": " read w1 w2

But it breaks the line using space as well as a delimiter along with ':'
When I used

    IFS=":" 

150, .
?
"is" . ?

+3
1

awk:

cat file
Number of Iterations: 150
Average time is 45 ms
Average time for collisions is 50 ms
Total time is 95 ms
Number of Iterations: 200
Average time is 40 ms
Average time for collisions is 60 ms
Total time is 100 ms

awk '/^Total/{p=1} {gsub(/[^0-9]+/, ""); a[++i]=$0}
     p{print a[1], a[2], a[3], a[4]; p=0; delete a; i=0}' OFS=, file
150,45,50,95
200,40,60,100
0

All Articles