Given this specific line pulled from ifconfig, in my case:
inet 192.168.2.13 netmask 0xffffff00 broadcast 192.168.2.255
How could one extract the 192.168.2.13 part (the local IP address), presumably with regex?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Here’s one way using
grep:Results:
If you wish to select only valid addresses, you can use:
Results:
Otherwise, just select the fields you want using
awk, for example:Results:
Addendum:
Word boundaries:
\b