在bash脚本中使用多字符分隔符

在bash脚本中使用多字符分隔符,bash,ifs,Bash,Ifs,我有一个文本文件,其中的数据格式为: Number of Iterations: 150 Average time is 45 ms Average time for collisions is 50 ms Total time is 95 ms .... 这类文件有多个。我必须阅读所有这些文件,并制作一个csv文件,其中包含以下表格条目: 150,45,50,95 200,40,60,100 ... ... 其中每行对应一个txt文件。 我正在编写一个bash脚本,以根据此数据生成CSV

我有一个文本文件,其中的数据格式为:

Number of Iterations: 150
Average time is 45 ms
Average time for collisions is 50 ms
Total time is 95 ms
....
这类文件有多个。我必须阅读所有这些文件,并制作一个csv文件,其中包含以下表格条目:

150,45,50,95
200,40,60,100 
...
...
其中每行对应一个txt文件。
我正在编写一个bash脚本,以根据此数据生成CSV文件。
我只想从文本文件中读取数字。
对于第一行,我尝试使用

    IFS =": " read w1 w2
但它通过使用空格和“:”分隔行
当我使用

    IFS=":" 
在我不想要的150号门前印了一个额外的空格。
我该怎么做
同样在第二行中,我想使用“is”作为分隔符。允许吗?
谢谢

您可以使用此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

您可以在示例输入和预期输出中发布更多行吗。