#-h- uniq.r 1438 asc 25-apr-81 09:11:14 [002,100] #-h- main 624 asc 25-apr-81 09:07:52 [002,100] ## uniq -strip adjacent duplicate lines DRIVER(uniq) character buf(MAXLINE) integer open, getarg integer i, int, count data count /NO/ call query("usage: uniq [-c] [file] ...") for (i=1; getarg(i, buf, MAXLINE) != EOF; i=i+1) { if (buf(1) == MINUS & (buf(2) == LETC | buf(2) == BIGC)) { count = YES next } else if (buf(1) == MINUS & buf(2) == EOS) int = STDIN else { int = open(buf,READ) if (int == ERR) call cant(buf) } call unique (int, count) if (int != STDIN) call close(int) } if (i == 1 | (i == 2 & count == YES)) #read from STDIN call unique (STDIN, count) DRETURN end #-h- unique 690 asc 25-apr-81 09:07:54 [002,100] ## unique - locate duplicate lines in file int subroutine unique (int, count) integer equal, getlin integer t, count, k character buf1(MAXLINE), buf2(MAXLINE) t = getlin(buf1, int) while (t != EOF) { k = 1 for (t=getlin(buf2,int); t!= EOF; t=getlin(buf2,int)) { if (equal(buf1, buf2) == NO) break k = k + 1 } if (count == YES) { call putdec(k, 5) call putc(BLANK) } call putlin(buf1, STDOUT) if (t == EOF) break k = 1 for (t=getlin(buf1,int); t!= EOF; t=getlin(buf1,int)) { if (equal(buf1,buf2) == NO) break k = k + 1 } if (count == YES) { call putdec(k, 5) call putc(BLANK) } call putlin(buf2, STDOUT) } return end #-h- uniq.rof 887 asc 11-may-81 12:19:16 [002,100] .pl 60 .bp .rm 70 .in 0 .he 'UNIQ'1/11/79'UNIQ' .fo ''-#-' .fi NAME .br .in 7 uniq - strip adjacent repeated lines from a file .sp 1 .in SYNOPSIS .br .in 7 uniq [-c] [file] ... .sp 1 .in DESCRIPTION .br .in 7 Uniq reads the input file(s), comparing adjacent lines. Second and succeeding copies of repeated lines are removed; the remainder is written to standard output. If the '-c' flag is given, each line is preceded by a count of the number of occurrences of that line. .sp 1 .in FILES .br .in 7 .sp 1 .in SEE ALSO .br .in 7 The tool 'comm'; the Unix command 'uniq' .sp 1 .in DIAGNOSTICS .br .in 7 A message is printed if an input file cannot be opened and processing is terminated. .sp 1 .in AUTHORS .br .in 7 .sp 1 Originally from Kernighan and Plauger's 'Software Tools', with modifications by Debbie Scherrer. .sp 1 .in BUGS .br .in 7