General discussion
March 31, 2003 at 09:20 AM
joseph moore

Looking for command-line tool

by joseph moore . Updated 23 years, 6 months ago

Hello all.
I am trying to find a command-line tool that will sort through a TXT file, and write only unique lines into another TXT file.

Here is my situation: every day in my user’s login scripts, I write to a single TXT file the user name andcomputer that the user just logged into. For example, the file looks like this:

MACHINE1|BOB
MACHINE2|JOE
MACHINE3|TOM
MACHINE4|JAN
MACHINE2|JOE
MACHINE5|TIM
MACHINE1|BOB
etc.

The line in my login script is this:
ECHO %COMPUTERNAME%|%USERNAME% >>LOGFILE.TXT

Now, what I want to do is sort this file by unique records. Every day, I log into my machine, so I have a bunch of records with my login logging into my workstation in this TXT file. I want to make a summary report to just list the individual records from my log file into a single TXT file. That’s all. Nothing fancy. No report headers, logos, or anything like that. This is just for me.

So in my example above, this tool would create output like this:

MACHINE1|BOBMACHINE2|JOE
MACHINE3|TOM
MACHINE4|JAN
MACHINE5|TIM

(see, the duplicate records for JOE and BOB are gone)

I DON’T want to pull this file into a database and do a unique sort on it. I don’t want to pull this into a spreadsheet and sort it and discard duplicates. I just want something I can put in a BAT file to run. Just a simple command line tool that reads in a TXT file, and pulls out all unique records. No GUI, no button clicking, nothing like that.

I tried to get this to work using FOR /F command, and the SORT command, and even the LIST command (all DOS-era command line commands) to no avail.

This discussion is locked

All Comments