If a VBscript is acceptable, I believe this does what you want. Test on a
*copy* of your data first.
-----begin munge-data.vbs-----
'Note:
'If any file has less than 3 lines this script will error out on that file.
'If this script won't be run from the directory containing the text files,
'change this to that directory's FULL PATH:
Const WORKINGDIR = "."
'Set your desired delimiter here:
Const DELIMITER = ","
'If there are already files named *.tmp in this directory, change this:
Const TMPEXT = "tmp"
Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8
Const CreateFile = -1
Const DontCreateFile = 0
Const Unicode = -1
Const ASCII = 0
Set FSO = CreateObject("Scripting.FileSystemObject")
Set working = FSO.GetFolder(WORKINGDIR)
For Each file In working.Files
If ".txt" = LCase(Right(file, 4)) Then
Set fileIn = FSO.OpenTextFile(file, ForReading, DontCreateFile, ASCII)
Set fileOut = FSO.OpenTextFile(Left(file, Len(file) - Len(TMPEXT)) & _
TMPEXT, ForWriting, CreateFile, ASCII)
'Ignore first 3 lines:
thisLine = fileIn.ReadLine
thisLine = fileIn.ReadLine
thisLine = fileIn.ReadLine
Do Until fileIn.AtEndOfStream
thisLine = RTrim(fileIn.ReadLine)
tmp = 0
Do
'Replace *all* runs of 2 or more spaces with the delimiter:
tmp = InStr(tmp + 1, thisLine, " ")
If tmp < 1 Then Exit Do
For L0 = tmp + 2 To Len(thisLine)
If Mid(thisLine, L0, 1) <> " " Then
thisLine = Left(thisLine, tmp - 1) & DELIMITER & _
Mid(thisLine, L0)
Exit For
End If
Next
Loop
fileOut.WriteLine thisLine
Loop
fileIn.Close
fileOut.Close
file.Delete
End If
Next
For Each file In working.Files
If ("." & TMPEXT) = LCase(Right(file, Len(TMPEXT) + 1)) Then _
file.Move Left(file, Len(file) - Len(TMPEXT)) & "txt"
Next
-----end munge-data.vbs-----
--
Mercy is a shield used by the weak.