I am sure there are better ways but you could save the current ip and check it?
#!/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 * next if ($save eq $_); #new if matching print sort $_; $save = $_; #save it $count ++; # Count } print "\n"; print "Total IP'S = $count\n"; HTH Ned Cunningham POS Systems Development Monro Muffler Brake 200 Holleder Parkway Rochester, NY 14615 (585) 647-6400 ext. 310 [EMAIL PROTECTED] -----Original Message----- From: rmck [mailto:[EMAIL PROTECTED] Sent: Thursday, March 18, 2004 12:44 PM To: [EMAIL PROTECTED] Subject: sort stdin and print 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??? 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 $_; $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> -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>