unique entries needed

Hi All,

I have the following command which returns the output like this -

wget URL|grep hostname|awk '{print $1,$3}'|/usr/bin/perl -nle 'm{"(.*?)".*?//(.*):(\d+)/} and print "$1 $2 $3"'|while read host port
do
echo check_env_$port
echo host
done

OUTPUT
Appname hostname port
Appname2 hostname port2 ...

Appnames are all unique , while hostname is not since I am grepping for single hostname(vip).
Some of the ports are not unique so I am getting the same port for 4-5 different appnames.

Within the same snippet of code I want to add a number to echo command so the its unique..
e.g. check_env_1_1234
check_env_2_1234

So for port 1234 it should increment the numbers.

If that's too hard then atleast get unique entries so that I don't get check_env_1234 not more than once which ever comes first and ignore the rest of the entries with the same port.

Thanks,
Jack.

I wonder how this works at all. It looks like host will be assigned the value of $1, while port will be assigned "$2 $3".

... and print "$1 $2 $3"'|while read host port

But in any case, you could create a variable per port number, say n1234 for port 1234, and use it to store the count like this:

test -z "$(eval echo \$n$port)" && n${port}=1 || ((n${port}++))

Then you could print out your command like this:

eval echo check_env_\$n${port}_$port