Heya, I have a small problem i need some help with.

I have a directory of CSV files about 250 of them, that i need to search
though and and generate some totals from.

I can quite easily join all the files together using a 'copy *.csv
full-list.csv' so that i need only work on one file rather than work my
way though a the directory one by one.

The files contain a non unique id (unique to the file, but not the set
of files) followed by a name. So it looks like this;

a,katie,
a,natasha,
a,monica,
...
etc

There are 250 files like this. What i need to do is find all the unique
names in the whole set (all the files) and then how many times those
names occur. i.e. how many 'katies' occur across all 250 files.

This needs to be outputted just as each unique name and a total.

kate,15,
monica,11,
natasha,4,

Also if it is possible i'd also like to have the id's that occur with
each occurrence of a unique name outputted in some manner. Perhaps as a
quoted encapsulated string in a third column. Something like this....

katie,15,"a,b,c,d,e"

All seems a tiny bit complicated and a bit much to get my head around.
Can anyone have a shot provide code that will provide me with the unique
names and the total occurrences?

Many thanks in advance,

Hardeep.

Re: Searching a CSV and Totaling Unique Occurrences of Strings within. by Fosco

Fosco
Wed May 26 23:42:45 CDT 2004

"Hardeep Rakhra"

a simple starting point :
then www.google.com "read+csv+file"
http://download.microsoft.com/download/winscript56/Install/5.6/W982KMeXP/EN-US/scrdoc56en.exe

sDirectory = "C:\temp" 'your *.csv files folder
sLogFile = "C:\CSV.Log"
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oLogFile = oFSO.OpenTextFile(sLogFile, 8, True, 0)
Set oFolder = oFSO.GetFolder(sDirectory)
For Each oFile In oFolder.Files
If InStr(UCase(oFile.Name), ".CSV") Then
Set oStream = oFSO.OpenTextFile(oFile.Path, 1)
Do Until oStream.AtEndOfStream
sLine = oStream.ReadLine
cLine = oStream.Line
If InStr(LCase(sLine),"monica") Then
oLogFile.WriteLine sLine & oFile.Path &" line " & cLine
End If
Loop
End If
Next
oLogFile.Close

--
Fosco