Solved

How do I get a list of all the ipaddresses in one string?

Posted on 2013-02-06
2
258 Views
Last Modified: 2013-02-07
Hi
How do I get a list of all the ipaddresses (that is not 127.0.0.1) in one string?
IPv4 and IPv6 addresses.
so return "IP:10.20.30.1, IP:10.20.30.2, IP:3030:0:110:715:150:51ff:fe82:4f15"

Thanks
Jamie
0
Comment
Question by:jamie_lynn
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 19

Accepted Solution

by:
bevhost earned 500 total points
ID: 38862398
#!/bin/bash
for line in `ip addr show | grep inet | grep -v host | cut -d\  -f6 | cut -d/ -f1 `; do
        if [ "x$str" == "x" ]; then
                str="IP:$line"
        else
                str="$str, IP:$line"
        fi
done
echo $str

Open in new window

0
 

Author Closing Comment

by:jamie_lynn
ID: 38865027
Works great! Thanks!
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Have you ever been frustrated by having to click seven times in order to retrieve a small bit of information from the web, always the same seven clicks, scrolling down and down until you reach your target? When you know the benefits of the command l…
The purpose of this article is to fix the unknown display problem in Linux Mint operating system. After installing the OS if you see Display monitor is not recognized then we can install "MESA" utilities to fix this problem or we can install additio…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question