home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C!T ROM 2
/
ctrom_ii_b.zip
/
ctrom_ii_b
/
PROGRAM
/
C
/
UNIQUE
/
READ.ME
next >
Wrap
Text File
|
1992-12-20
|
4KB
|
177 lines
UNIQUE.EXE
----------
UNIQUE.EXE
----------
This program is a DOS filter which allows a user to remove duplicate
lines from a pre-sorted text file. Optionally, it prepends each output
line with the number of occurrences of that line in the input stream.
Legal Stuff
-----------
The software and this documentation are provided "as is." Ed Beroset
(the author) makes no warranty, express or implied with respect to the
software and/or user documentation and specifically disclaims the
implied warranties of merchantability and fitness for a particular
purpose. The author does not warrant that the software and/or the user
documentation will meet your requirements or expectations or that the
operation of the software will be uninterrupted and/or error free.
Operation
---------
Since UNIQUE is a DOS filter, like SORT or FIND or MORE which come with
most flavors of DOS, if you simply type "UNIQUE" from the command line,
you won't get much. Type UNIQUE -? at the command line and the program
will tell you about itself. The usual way to use the program is as
follows. Let's say that we have a short text file called NAMES.RAW:
--- contents of NAMES.RAW ---
Ken
George
Lisa
Keith
George
Scott
Richard
Steve
George
George
Ron
Ron
Anita
Ed
Ed
Scott
Scott
--- end of NAMES.RAW ---
In order to use unique, you'll first need to sort the file. This is
done with the following command:
SORT <NAMES.RAW >NAMES.SRT
The "<" and ">" characters are called redirectors. They're covered in
your DOS manual, (fascinating reading), but basically "<" means "read
from the following named device or file instead of from the keyboard"
and ">" means "write to the following named device or file instead of to
the screen." The result of the command line above is that the NAMES.RAW
file is run through the SORT filter and the results are written to
NAMES.SRT which now looks like this:
--- contents of NAMES.SRT ---
Anita
Ed
Ed
George
George
George
George
Keith
Ken
Lisa
Richard
Ron
Ron
Scott
Scott
Scott
Steve
--- end of NAMES.SRT
Now that the file is sorted, we may run it through the UNIQUE filter.
The command is similar:
UNIQUE <NAMES.SRT >NAMES.UNQ
All duplicate lines are removed from the input file NAMES.SRT and
written to NAMES.UNQ which now looks like this:
--- contents of NAMES.UNQ ---
Anita
Ed
George
Keith
Ken
Lisa
Richard
Ron
Scott
Steve
--- end of NAMES.UNQ ---
If you don't need the intermediate file NAMES.SRT, you can amaze your
friends and neighbors by doing it all in one step like this:
SORT <NAMES.RAW | UNIQUE >NAMES.UNQ
The "|" character is called a pipe and it causes the output of one
process or program to be used the input to another. (Read more about it
in your DOS manual.) In this case, the output of SORT is used as the
input of UNIQUE, which is exactly what we want.
Let's say that in this case, we want to find out how many times each
line appeared in the original. UNIQUE can count 'em for you. Try this:
SORT <NAMES.RAW | UNIQUE -c >NAMES.CNT
The "-c" is a command line switch (did I mention the DOS manual?) which
tells UNIQUE to prepend each line with a count of the lines in the
original (e.g. input) file.
--- contents of NAMES.CNT ---
1:Anita
2:Ed
4:George
1:Keith
1:Ken
1:Lisa
1:Richard
2:Ron
3:Scott
1:Steve
--- end of NAMES.CNT ---
If you want to sort this by frequency of occurrence, from highest to
lowest, you could run this file through SORT and get another file, or
you could do all of these operations in a single step:
SORT <NAMES.RAW | UNIQUE -c | SORT /R >NAMES.FRQ
--- contents of NAMES.FRQ ---
4:George
3:Scott
2:Ron
2:Ed
1:Steve
1:Richard
1:Lisa
1:Ken
1:Keith
1:Anita
--- end of NAMES.FRQ ---
All sorts of fancy command line tricks are possible, but I'll let you
discover them for yourself. You might want to look through your DOS
manual. ;-)
Author
------
This program was written by Ed Beroset. It's freeware, so don't even
TRY to send me any money. You may reach me through FIDOnet at
1:3641/1.250. (That's Psychotronic BBS in Durham, North Carolina, USA,
919-286-7738.)