Cut out extra lines only when present. Linux
===

Okay so I have a list of addresses and next them there is a port number. The thing is that isn't always true. For example I have this list:

    www.google.com:80
    www.gmail.com:8080
    www.yahoo.com
    www.msn.com:443
    www.amazon.com
    www.apple.com
    www.hotmail.com

The thing I want to do is go through the text file that holds this list line by line and cut out the address and if there is a port number after the `.com ` then cut that port number out and store it in a variable. This is what I tried:

    for each in `cat address.txt`; do
    	f_address=$each
    	f_port=`echo $each | cut -d":" -f2`
    	
    	if [[ "$f_address" == *:* ]]; then
    		address=`echo $f_address | cut -d":" -f1`
    	else
    		address=$f_address
    	fi
    	
    	if [ "$f_port" = "*" ]; then
    		port=$f_port
    	else
    		port="443"
    	fi
When this is run it doesn't take what is after the `:` when needed instead it just makes it `443`. 