Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to parse the output file from contig.exe into a a comma-separated value file. I've developed a method to do this is Notepad++, but given the number of files I have to parse (hundreds of text files) I would like to have an automated method using either command-line or PowerShell.

For example, I would like to turn this:

Contig v1.7 - Makes files contiguous
Copyright (C) 1998-2012 Mark Russinovich
Sysinternals -

Processing E:\$Mft...
E:\$Mft is in 80309 fragments

Processing E:\$Mft::$BITMAP...
E:\$Mft::$BITMAP is in 2202 fragments

     Number of files processed   : 2
     Average fragmentation       : 41255.5 frags/file

...into this:

E:\$Mft,80309 fragments
E:\$Mft::$BITMAP,2202 fragments

Any ideas? Thanks!

share|improve this question
I'm sure Notepad++ allows you to search+replace in multiple files at once, and you can probably use RegEx to retain only the lines that start with "Drive:\" and end in "fragments". – Karan Jan 3 '13 at 17:46
up vote 1 down vote accepted

In powershell, you just apply your regex using the -match operator and then output each match separated by commas:

contig.exe | foreach-object{ if($_ -match "(.*) is in (.*)") {"`"$($Matches[1])`",`"$($Matches[2])`""}} 


"E:\$Mft","80309 fragments" 
"E:\$Mft::$BITMAP","2202 fragments"

Note that I have enclosed the columns with quotes to handle columns with spaces

share|improve this answer
That worked! Thank you very much! – Jerry Sweeton Jan 3 '13 at 21:43
@Jerry, if it worked, you should accept it as the answer. – dangph Jan 21 '13 at 0:21

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .