1 # Copyright (C) 2001-2008, Parrot Foundation.
6 examples/pir/uniq.pir - Remove duplicate lines from a sorted file
10 % ./parrot examples/pir/uniq.pir -o uniq.pbc
14 Parrot implementation of C<uniq>. Removes duplicate lines from a sorted
15 file. You'll have to create a suitable file to "de-dup".
17 =head2 Command-line Options
23 Precede each output line with the count of the number of times the
24 line occurred in the input, followed by a single space
28 Don't output lines that are not repeated in the input
32 Don't output lines that are repeated in the input
38 By Leon Brocard <acme@astray.com>.
40 Converted to PIR by Bernhard Schmalhofer.
52 if num_args > 0 goto SOURCE
53 print "usage: parrot "
55 print " [-c] [-d] [-u] filename\n"
59 # set up flag registers
63 # do some simple option parsing
73 $I11 = 1 # duplicate mode
78 $I12 = 1 # unique mode
82 .local string file_name
87 in_fh = open file_name, 'r'
89 .local string prev_line, curr_line
90 prev_line = readline in_fh
94 curr_line = readline in_fh
96 if curr_line == prev_line goto MATCH
102 # we go to some lengths to make the count pretty
117 # show duplicates mode
123 print "Couldn't read "
130 # don't show lines that are duplicated mode
150 set prev_line, curr_line
151 if curr_line, SOURCE_LOOP
162 # vim: expandtab shiftwidth=4 ft=pir: