Delete duplicated lines [solved]

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
dwngrt
Posts: 26
Joined: 07 Oct 2013 05:14
Location: The Netherlands

Delete duplicated lines [solved]

#1 Post by dwngrt » 14 Oct 2013 02:14

Thanks a lot to everyone who helped me so far with fine-tuning my chat script!
i am working on a new update for it :)
the thing is i need to auto delete duplicated lines in a txt file, here is a piece of the script:

Code: Select all

:support
echo %current%>>users.txt
(
set /p user1=
set /p user2=
set /p user3=
set /p user4=
set /p user5=
set /p user6=
set /p user7=
)<users.txt

:main
cls
set name=%current%
echo ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ» ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
echo ºwelcome to the support centerº ³Others using this script:
echo ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ ³%user1%
echo ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿ ³%user2%
echo ³Make your sellection bellow  ³ ³%user3%
echo ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´ ³%user4%
echo ³[1]-Collor menu              ³ ³%user5%
echo ³[2]-Chat name                ³ ³%user6%
echo ³[3]-Chatroom                 ³ ³%user7%
echo ³[4]-Info (w.i.p)             ³ ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
echo ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ


it looks messy i know, sorry for that ^^

rodrigolima
Posts: 21
Joined: 19 Jul 2013 11:35
Location: Brazil

Re: Delete duplicated lines [solved]

#2 Post by rodrigolima » 27 Nov 2013 05:29

Hello dwngrt

Just Today I saw your post here at DOSTIPS forum.
So I hope that it help you.

Take a look at the code below:

Code: Select all


@echo off
cls
title Batch - Clean Duplicated Lines

::Rodrigo Sant Anna Lima
:: This is my Challenge Batch: Remove Duplicated Lines
:: 05/07/2013

if exist validated.txt del validated.txt

:: Read and sort file
For /F "tokens=* delims=" %%i in ('sort OriginInput.txt') do (
   findstr /ixc:"%%i" unique.txt 2>errors.txt || >> unique.txt echo.%%i
)

cls
PING 1.1.1.1 -n 1 -w 2000 >NUL
cls
goto Finish
goto eof

:Finish
del errors.txt
ren unique.txt validated.txt

:eof
goto:eof


For example, create a text file called "OriginInput.txt" and put

Kratos
Athena
Greece
Sparta
Poseidon
Zeus
Hades
Perseus
Kratos
Aphrodite

Run Batch and check file "validated.txt" and see that duplicated lines ("Kratos") was deleted.

Greetings from Brazil
See You

Post Reply