#!/bin/bash # To be used with nmap grepable output (-oG option) if [ -z $1 ]; then echo "Usage: $(basename $0) " exit -1 fi ports="`cat $1 | grep -oP '\s\K[0-9]+(?=/)'`" echo $ports | xargs | sed 's/ /,/g'