Solved Delete repeated names from a txt file

January 4, 2012 at 04:21:19
Specs: Windows 7
Hi,
I have some txt files and need to remove the lines that have repeated names.
Example:

John
Mary
Adam
Adam
Adam

In this example I need a batch to remove the two repeated Adam.
Thanks in advance.


See More: Delete repeated names from a txt file

Report •

#1
January 7, 2012 at 16:25:37
✔ Best Answer
Hi xander_91,

This will take a list of names (names.txt) like the one in your example, and create a new file (names_without_dupes.txt) that doesn't contain duplicates. If you want we could change it to rewrite your original names.txt without dupes. Here you go...

@echo off
setlocal enabledelayedexpansion
for /f "tokens=* delims= " %%a in (names.txt) do (
set str=%%a
find /i ^"!str!^" names.txt
find /i ^"!str!^" names_without_dupes.txt
if errorlevel 1 echo !str!>>names_without_dupes.txt
)


Report •

#2
January 8, 2012 at 11:38:19
Thanks a lot jowah.
That's what I've been looking for.

Report •
Related Solutions


Ask Question