Discussion forum for all Windows batch related topics.
Moderator: DosItHelp
-
alleypuppy
- Posts: 82
- Joined: 24 Apr 2011 19:20
#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!

-
renzlo
- Posts: 116
- Joined: 03 May 2011 19:06
#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
#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!

-
renzlo
- Posts: 116
- Joined: 03 May 2011 19:06
#4
Post
by renzlo » 19 Nov 2011 22:50
glad i'd help you.
-renzlo