home *** CD-ROM | disk | FTP | other *** search
/ C!T ROM 2 / ctrom_ii_b.zip / ctrom_ii_b / PROGRAM / C / UNIQUE / READ.ME next >
Text File  |  1992-12-20  |  4KB  |  177 lines

  1.  
  2.  
  3.  
  4.                                UNIQUE.EXE
  5.                                ----------
  6.  
  7.  
  8. UNIQUE.EXE
  9. ----------
  10.  
  11. This program is a DOS filter which allows a user to remove duplicate
  12. lines from a pre-sorted text file.  Optionally, it prepends each output
  13. line with the number of occurrences of that line in the input stream.
  14.  
  15.  
  16. Legal Stuff
  17. -----------
  18.  
  19. The software and this documentation are provided "as is."  Ed Beroset
  20. (the author) makes no warranty, express or implied with respect to the
  21. software and/or user documentation and specifically disclaims the
  22. implied warranties of merchantability and fitness for a particular
  23. purpose. The author does not warrant that the software and/or the user
  24. documentation will meet your requirements or expectations or that the
  25. operation of the software will be uninterrupted and/or error free.
  26.  
  27.  
  28. Operation
  29. ---------
  30.  
  31. Since UNIQUE is a DOS filter, like SORT or FIND or MORE which come with
  32. most flavors of DOS, if you simply type "UNIQUE" from the command line,
  33. you won't get much.  Type UNIQUE -? at the command line and the program
  34. will tell you about itself.  The usual way to use the program is as
  35. follows.  Let's say that we have a short text file called NAMES.RAW:
  36.  
  37. --- contents of NAMES.RAW ---
  38. Ken
  39. George
  40. Lisa
  41. Keith
  42. George
  43. Scott
  44. Richard
  45. Steve
  46. George
  47. George
  48. Ron
  49. Ron
  50. Anita
  51. Ed
  52. Ed
  53. Scott
  54. Scott
  55. --- end of NAMES.RAW ---
  56.  
  57. In order to use unique, you'll first need to sort the file.  This is
  58. done with the following command:
  59.  
  60. SORT <NAMES.RAW >NAMES.SRT
  61.  
  62. The "<" and ">" characters are called redirectors.  They're covered in
  63. your DOS manual, (fascinating reading), but basically "<" means "read
  64. from the following named device or file instead of from the keyboard"
  65. and ">" means "write to the following named device or file instead of to
  66. the screen."  The result of the command line above is that the NAMES.RAW
  67. file is run through the SORT filter and the results are written to
  68. NAMES.SRT which now looks like this:
  69.  
  70. --- contents of NAMES.SRT ---
  71. Anita
  72. Ed
  73. Ed
  74. George
  75. George
  76. George
  77. George
  78. Keith
  79. Ken
  80. Lisa
  81. Richard
  82. Ron
  83. Ron
  84. Scott
  85. Scott
  86. Scott
  87. Steve
  88. --- end of NAMES.SRT
  89.  
  90. Now that the file is sorted, we may run it through the UNIQUE filter.
  91. The command is similar:
  92.  
  93. UNIQUE <NAMES.SRT >NAMES.UNQ
  94.  
  95. All duplicate lines are removed from the input file NAMES.SRT and
  96. written to NAMES.UNQ which now looks like this:
  97.  
  98. --- contents of NAMES.UNQ ---
  99. Anita
  100. Ed
  101. George
  102. Keith
  103. Ken
  104. Lisa
  105. Richard
  106. Ron
  107. Scott
  108. Steve
  109. --- end of NAMES.UNQ ---
  110.  
  111. If you don't need the intermediate file NAMES.SRT, you can amaze your
  112. friends and neighbors by doing it all in one step like this:
  113.  
  114. SORT <NAMES.RAW | UNIQUE >NAMES.UNQ
  115.  
  116. The "|" character is called a pipe and it causes the output of one
  117. process or program to be used the input to another.  (Read more about it
  118. in your DOS manual.)  In this case, the output of SORT is used as the
  119. input of UNIQUE, which is exactly what we want.
  120.  
  121. Let's say that in this case, we want to find out how many times each
  122. line appeared in the original.  UNIQUE can count 'em for you.  Try this:
  123.  
  124. SORT <NAMES.RAW | UNIQUE -c >NAMES.CNT
  125.  
  126. The "-c" is a command line switch (did I mention the DOS manual?) which
  127. tells UNIQUE to prepend each line with a count of the lines in the
  128. original (e.g. input) file.
  129.  
  130. --- contents of NAMES.CNT ---
  131.    1:Anita
  132.    2:Ed
  133.    4:George
  134.    1:Keith
  135.    1:Ken
  136.    1:Lisa
  137.    1:Richard
  138.    2:Ron
  139.    3:Scott
  140.    1:Steve
  141. --- end of NAMES.CNT ---
  142.  
  143. If you want to sort this by frequency of occurrence, from highest to
  144. lowest, you could run this file through SORT and get another file, or
  145. you could do all of these operations in a single step:
  146.  
  147. SORT <NAMES.RAW | UNIQUE -c | SORT /R >NAMES.FRQ
  148.  
  149. --- contents of NAMES.FRQ ---
  150.    4:George
  151.    3:Scott
  152.    2:Ron
  153.    2:Ed
  154.    1:Steve
  155.    1:Richard
  156.    1:Lisa
  157.    1:Ken
  158.    1:Keith
  159.    1:Anita
  160. --- end of NAMES.FRQ ---
  161.  
  162. All sorts of fancy command line tricks are possible, but I'll let you
  163. discover them for yourself.  You might want to look through your DOS
  164. manual.  ;-)
  165.  
  166.  
  167. Author
  168. ------
  169.  
  170. This program was written by Ed Beroset.  It's freeware, so don't even
  171. TRY to send me any money.  You may reach me through FIDOnet at
  172. 1:3641/1.250.  (That's Psychotronic BBS in Durham, North Carolina, USA,
  173. 919-286-7738.)
  174.  
  175.  
  176.  
  177.