127.0.0.1 c2.gostats.com #SpySweeper.Spy.Cookie
127.0.0.1 ads.goyk.com
# 1-800-hostingAS3321069.41.160.0 - 69.41.191.255
127.0.0.1 2a02:598:2::1095
so i want to clean the old file by removing comments, and duplicates, so far i havemy @array = (); $#array = -1; my @tmp_array = (); $#tmp_array = -1; my @uniq = (); $#uniq = -1; my $i = 0; open(HOST_ORIG,'<', $file_read ) or die "Can't open $file_read: $!"; chomp(@array = <HOST_ORIG>); foreach $i (4...scalar(@array)-1) { (my $local_127, $tmp_array[$i] )=split(" ",$array[$i]); }; close(HOST_ORIG); my %seen; my @uniq = grep {! $seen{$_}++} sort(@tmp_array); open(TEMP, '>', $file_write)|| die "\n error opening file $file_write +\n"; print TEMP "#Hosts file\n"; print TEMP "#Last Modified -> ". localtime() . "\n"; print TEMP "# \n"; print TEMP "# localhost: Needs to stay like this to work\n"; print TEMP "127.0.0.1\t localhost\n"; print TEMP "# \n"; foreach $i (1...scalar(@uniq)-1) { print TEMP "127.0.0.1\t $uniq[$i]\n"; } close(TEMP);
it works except when there are 3 or more columns, the 3rd and 4rth columns get wrapped around to a new line like this
127.0.0.1 c2.gostats.com
how do i throw away the rest of the line if it exists?
Thanks!
In reply to parsing a terrible /etc/hosts by f77coder
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |