src/utils/jkUniq/jkUniq.c 1.4

1.4 2009/10/16 22:17:04 markd
added warning that it overwrite input; fixed bug in count
Index: src/utils/jkUniq/jkUniq.c
===================================================================
RCS file: /projects/compbio/cvsroot/kent/src/utils/jkUniq/jkUniq.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -b -B -U 1000000 -r1.3 -r1.4
--- src/utils/jkUniq/jkUniq.c	10 Jun 2003 17:19:33 -0000	1.3
+++ src/utils/jkUniq/jkUniq.c	16 Oct 2009 22:17:04 -0000	1.4
@@ -1,66 +1,69 @@
 /* jkUniq - pass input to output a line at a time, but only
  * pass through lines haven't seen before. */
 #include "common.h"
 #include "hash.h"
 #include "linefile.h"
 
 static char const rcsid[] = "$Id$";
 
 void usage()
 /* Explain usage and exit */
 {
 errAbort(
 "jkUniq - remove duplicate lines from file.  Lines need not\n"
 "be next to each other (plain Unix uniq works for that)\n"
+"\n"
+"WARNING: this overwrites the input files\n"
+"\n"
 "usage:\n"
 "    jkUniq file(s)");
 }
 
 void jkUniq(char *fileName)
 /* Remove dupe lines from file. */
 {
 struct slName *lineList = NULL, *lineEl;
 struct lineFile *lf = lineFileOpen(fileName, TRUE);
 char *line;
 int lineSize;
 struct hash *hash = newHash(0);
 FILE *f;
 
 while (lineFileNext(lf, &line, &lineSize))
     {
     if (!hashLookup(hash, line))
 	{
 	hashAdd(hash, line, NULL);
 	lineEl = newSlName(line);
 	slAddHead(&lineList, lineEl);
 	}
     }
 slReverse(&lineList);
 lineFileClose(&lf);
 f = mustOpen(fileName, "w");
 for (lineEl = lineList; lineEl != NULL; lineEl = lineEl->next)
     {
     fputs(lineEl->name, f);
     fputc('\n', f);
     }
 fclose(f);
 slFreeList(&lineList);
 freeHash(&hash);
 }
 
 int main(int argc, char *argv[])
 /* Process command line. */
 {
 int i;
 
 if (argc < 2)
     usage();
 for (i=1; i<argc; ++i)
     {
     char *fileName = argv[i];
-    printf("Uniqing %s (%d of %d)\n", fileName, i, argc);
+    printf("Uniqing %s (%d of %d)\n", fileName, i, argc-1);
     jkUniq(fileName);
     }
 return 0;
 }