> HI > > I have a script that reads stdin from the output of another script and cleans it up and prints it. The script gets ip's. > > I would like to sort it and and eliminate duplicates count the sorted/unique ips then print???
Ok then do that ;-).... > > I thought using the perl sort command would help but it did not... I could pipe the output to /bin/sort -u, but I wanted to do everthing in perl. > > Help if you can. > > #!/usr/bin/perl > use strict; > my $count = 0; > > while( <> ) { #read from stdin one line or record at a time > > s/ipadd://; #if line has ipadd: remove it > s/^ |\t//; #if any whitespace at the beginning of string rm > next if ($_=~/^\s*(\*|$)/); #if line begins with a * > > print sort $_; Right here you are sorting a single value and printing that. But you need the list of all values to sort, which means you will need to move your sort and print outside of the loop, and store the value to a temp location inside of the loop. Two easy ways to do this, with 'push' and an array, or since you only care about unique values, use a hash where the IP is the key. Then you would sort the keys of the hash. perldoc -f keys perldoc -f sort If this is confusing or doesn't get you there then let us know, http://danconia.org > $count ++; # Count > > } > print "\n"; > print "Total IP'S = $count\n"; > > > > Current out: > 111.222.81.97 > 111.222.81.97 > 111.111.135.11 > > Total IP'S = 3 > > > Goal Out: > 111.111.135.11 > 111.222.81.97 > > Total IP'S = 2 > > > Thanks, > rob > -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>