Page 1 of 1

[Resolved] delete duplicate mail in txt

Posted: 14 Jan 2009 04:27
by Acris
Hello

can you help me ?

In my contact list :

bidule@hotmail.com
bidouille@hotmail.com
tintin@gmail.com
archi@hotmail.com
bidule@hotmail.com
tintin@gmail.com
dan@gmail.com


I have a contact list with duplicate mails
I love him remove duplicate mails how?

i would like this :

bidule@hotmail.com


Please help me.

thanks

Acris

Posted: 16 Jan 2009 01:30
by DosItHelp
Acris,

Try this:

Code: Select all

@echo off
Setlocal
for /F "delims==" %%A in ('"set foundone[ 2>nul"') do set "%%A="
for /F %%A in (contacts.txt) do (
    if not defined foundone[%%A] (
        set "foundone[%%A]=Y"
        echo.%%A
    )
)

The first FOR loop removes all existing 'foundone[...' variables.
The second loop iterates through all entries in contact.txt.
First time an email is being processed a new 'foundone[email]' variable is created and the email is echoed.
If same email appears again then it will be skipped because the IF statement checks if a 'foundone[email]' variable with that email already exists.

DosItHelp? :wink:

Explaination needed !

Posted: 20 Jan 2009 09:10
by spam_killer
Hi DosItHelp, can you explain to me this part:

for /F "delims==" %%A in ('"set foundone[ 2>nul"') do set "%%A="


1. what the use "delims==" ?

2. what it is in ('"set foundone[ 2>nul"') ?


I cannot figure it. but thanks for this new trick.

Posted: 21 Jan 2009 04:34
by Acris
Thanks it works very well.

Posted: 16 Feb 2009 00:00
by spam_killer
actually you don't need this part.


for /F "delims==" %%A in ('"set foundone[ 2>nul"') do set "%%A="


Just copy this code and run:


for /F %%A in (contacts.txt) do (
if not defined foundone[%%A] (set "foundone[%%A]=Y"& echo.%%A)
)

Posted: 16 Feb 2009 10:21
by mhubers
Hi Spam_killer,

I think the reason for

for /F "delims==" %%A in ('"set foundone[ 2>nul"') do set "%%A="

is for doing house cleaning before you start parsing the file. You never know if the last time this script have junk in the env settings. Or user forgot to use setlocel.