Need help with a windows batch file

gutterseo

▬▬▬▬▬▬▬&
Feb 27, 2009
1,271
27
48
Howdy,

I need to write a batch script or something that can be natively run in vista to compar csv files.

The script must search for values in 1.csv that are also in 2.csv and then delete them from 2.csv.

If you guys have any ideas I am all ears.
 


Wouldn't have thought a batch file can provide such functionality..

Try 'compare two csv vista software' in your favourite search engine.
 
Sounds like you are scrubbing email lists perhaps?

As I recall...this command searches a file or files for text in a DOS prompt and dumps it to a text file named 1.txt

for %f in (12.txt) do find "stuff" %f >> 1.txt

That seaches the file 12.txt for the phrase "stuff" and dumps it to >> 1.txt - you should be able to write a batch that loops through file 1.

Of course, THAT is the slow-ass way to do it. What you really want to do is dump both to SQL tables and do joins to find duplicates. You can then filter those out to find single entries (ie, non duplicates) to get your data.

You could easily do that in access and import your CSV files to Access tables or (I think) use the CSV files natively using an ODBC text driver.

That was a bit high level - let me know if you need more detail.
 
Decided just to write it in python then use py2exe to make it executable. Will post the code here when I'm done. May be useful to someone down the line.
 
here is the python script I made. I know its a piece shit but its the first script I mad in python and I was dog tired and just needed something functional.

Code:
f = open("Datasources\mail.csv", "r")
minput = f.read()
iteminput = minput.split('\n')
f.close()
fiteminput = iteminput[:]

f = open("Downloads\completed.csv", "r")
moutput = f.read()
itemoutput = moutput.split('\n')
f.close()

imax = len(iteminput)
omax = len(itemoutput)
imax = imax - 1
omax = omax - 1
a = []

print "Removing Mails already completed"

i = 0
while i < imax:
    j = 0
    while j < omax:
        if iteminput[i] == itemoutput[j]:
            offend = iteminput[i]
            fiteminput.remove(offend)
        j = j + 1
    i = i + 1

first = fiteminput[0]
fiteminput.remove(first)
f = open("mail.csv", "w")
for line in fiteminput:      
    f.write(line + '\n')
f.close
If anyone thinks they'll need to use this just ask me and i'll explain the code.
 
Windows batch scripting just doesn't have the flexibility to do advanced text processing the way you can in Linux. My suggestions for this sort of problem (more for people reading the thread than for you, since you've obviously already solved the problem):

1.) Use a scripting language instead. You can download and install Python or Perl, or Windows has JScript and VBScript built-in (you run them with an app called cscript.exe that ships with every version of Windows since XP.)

2.) Use PowerShell. It's a download for Vista, or built-in on 7 (I think.) It does everything you want a shell to do, but it's also totally unlike anything you've ever used, so you're going to have to read the manual.

3.) If you're used to a Linux shell anyway, just install Cygwin. It's a Linux userland & bash shell for Windows; you can just write normal Linux shell scripts and they'll just work on Windows.
 
+1 for powershell, though all the ways mentioned or even a C++ exe would do the trick too.