[Resolved] delete duplicate mail in txt

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Acris
Posts: 5
Joined: 01 Jan 2009 11:44

[Resolved] delete duplicate mail in txt

#1 Post by Acris » 14 Jan 2009 04:27

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
Last edited by Acris on 21 Jan 2009 04:34, edited 1 time in total.

DosItHelp
Expert
Posts: 239
Joined: 18 Feb 2006 19:54

#2 Post by DosItHelp » 16 Jan 2009 01:30

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:

spam_killer
Posts: 12
Joined: 10 Oct 2008 04:50

Explaination needed !

#3 Post by spam_killer » 20 Jan 2009 09:10

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.

Acris
Posts: 5
Joined: 01 Jan 2009 11:44

#4 Post by Acris » 21 Jan 2009 04:34

Thanks it works very well.

spam_killer
Posts: 12
Joined: 10 Oct 2008 04:50

#5 Post by spam_killer » 16 Feb 2009 00:00

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)
)

mhubers
Posts: 4
Joined: 15 Feb 2009 21:29
Location: Madison, WI.

#6 Post by mhubers » 16 Feb 2009 10:21

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.

Post Reply