"Compress" the contents of a text file

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
alleypuppy
Posts: 82
Joined: 24 Apr 2011 19:20

"Compress" the contents of a text file

#1 Post by alleypuppy » 19 Nov 2011 20:01

Hello,

Is it possible to "compress" the contents of a text file? I have a log file with a lot of recurring computer names. I would like to know if I can shorten that list so each recurring name turns into just one name.

For instance, here are the contents of my file:
    dell-pc
    dell-pc
    dell-laptop
    dell-pc
    192.168.1.68
    192.168.1.71
    dell-pc
    dell-pc
    dell-laptop
    192.168.1.68
    192.168.1.68
    dell-laptop
    192.168.1.68
    dell-pc
    dell-pc
    dell-pc
    dell-pc
    dell-pc
    dell-pc

I would like to shorten the file to look like this:
    dell-pc
    dell-laptop
    192.168.1.68
    192.168.1.71

Is this possible?

Thanks for any input! :D

renzlo
Posts: 116
Joined: 03 May 2011 19:06

Re: "Compress" the contents of a text file

#2 Post by renzlo » 19 Nov 2011 21:03

you might to try this:

Code: Select all

@echo off

type nul>new_source.log
for /f "tokens=* delims=" %%a in (source.log) do (
findstr "%%a" "new_source.log">nul || echo %%a>>new_source.log
)


-renzlo

alleypuppy
Posts: 82
Joined: 24 Apr 2011 19:20

Re: "Compress" the contents of a text file

#3 Post by alleypuppy » 19 Nov 2011 21:55

renzlo wrote:you might to try this:

Code: Select all

@echo off

type nul>new_source.log
for /f "tokens=* delims=" %%a in (source.log) do (
findstr "%%a" "new_source.log">nul || echo %%a>>new_source.log
)


-renzlo
Thanks! That works perfectly! :D

renzlo
Posts: 116
Joined: 03 May 2011 19:06

Re: "Compress" the contents of a text file

#4 Post by renzlo » 19 Nov 2011 22:50

glad i'd help you.

-renzlo

Post Reply