Wednesday, February 10, 2016

Regex for turning a Dex profile text file into CSV

Text format
Type     Name                      Count   Time in  +Children  Minimum  
P Do Stuff script                  29513     25.15     25.42      0.00  

P Do other stuff script        288      7.94     22.78      0.00      0.31

CSV format
P Do Stuff script,29513,25.15,25.42,0.00  
P Do other stuff script,288,7.94,22.78,0.00,0.31

Regex to do this
0. Manually remove the header row

1. This puts a comma between the Type Name and Count columns
Replace ([\D\S])\s+([0-9]+) with \1,\2

2. This puts commas between all the numeric columns
Replace ([0-9]+)\s+([0-9]) with \1,\2

No comments:

Post a Comment