I'm trying to format the output from the following command;
MYIP=(/sbin/ifconfig $(getnic) | awk '/inet/ { print $2 } ' | sed -e s/addr://); echo $MYIP
which generates the following output;
172.30.0.1 fe80::42:c5ff:fecd:f09f 172.31.0.1 fe80::42:47ff:fe57:2f0d 172.17.0.1 fe80::42:a1ff:fe4e:2508 127.0.0.1 ::1 fe80::2887:fcff:fe19:e54b fe80::bc99:3aff:fe46:dcab fe80::b090:4cff:fecb:3dc4 fe80::9c0f:6dff:fe6b:6c71 fe80::808f:5fff:febb:2669 fe80::f851:23ff:fee4:c87a fe80::4c97:24ff:fe04:ea02 fe80::4cde:e2ff:feb7:4784 fe80::c4fc:4aff:fe67:1863 192.168.1.134 fe80::d1f1:947f:9370:74ca
How do I make it look nicer, just with each ipadress on a separate line?
Edit: clarification; for now I just want all ip's on a separate line, one each. Would be noce to strip out the v6 numbers, but htatäs really not important. Would be a bonux though.
I've tried with tr, sed, awk but I guess I'm doing something wrong or using the wrong command. My thought was just to add another pipe at the end that does some kind of word wrangling magic.
EDIT: This is the complete function;
function myip() {
MY_IP=$(/sbin/ifconfig $(getnic) | awk '/inet / { print $2 } ' | sed -e s/addr://| sort)
echo -e ${MY_IP:-"Not connected"}
}
But it still won't print linebreaks. Working on that. Thanx for all input
echo -e "$MYIP\n"
– ajgringo619 Oct 23 '19 at 23:03$
for command substitution. Please show the actual command. And use code formatting for the output, please – muru Oct 24 '19 at 00:04/inet /
(i.e. with a space). If you want to print MYIP with all its embedded spaces, then you need to double-quote it when you use it - e.g.echo "$MYIP"
instead ofecho $MYIP
. Also, the command-substitution should be double-quoted too:MYIP="$(...)"
. See Why does my shell script choke on whitespace or other special characters? – cas Oct 24 '19 at 08:32sed -e 's/addr://'
:-) – markgraf Oct 24 '19 at 15:18