#!/bin/bash nmap -sn `ip route | tail -1 | cut -d ' ' -f1` | sed -n 'n;p' | cut -c 22- | head -n -1 | awk '{tmp=$1; $1=$2; $2=tmp; gsub("\\(","",$1); gsub("\\)","",$1); printf "%-15s %s\n", $1, $2}' | sed 's/^ *//' # sed -n 'n;p' => FILTER odd lines # awk '{tmp=$1; $1=$2; $2=tmp; gsub("\\(","",$1); gsub("\\)","",$1); printf "%-15s %s\n", $1, $2}' => SWAP words and remove parenthesis # sed 's/^ *//' => REMOVE starting spaced