-5

Need only IP address as marked in the below image and nothing else.

PLEASE VIEW THIS IMAGE

Could someone please provide a specific bash command?

Pacifist
  • 3,025
  • 2
  • 12
  • 20
r00tk1ll3r
  • 63
  • 1
  • 10
  • 1
    Welcome to Stack Overflow. Please read the [**About**](http://stackoverflow.com/tour) page soon and also visit the links describing [**How to Ask a Question**](http://stackoverflow.com/questions/how-to-ask) and [**How to create a Minimal, Complete, and Verifiable example**](http://stackoverflow.com/help/mcve). Providing the necessary details, including your code, compiler warnings and associated errors, if any, will allow everyone here to help you with your question. – David C. Rankin Sep 22 '19 at 08:24
  • Please show the code and/or state the errors. Please don't use links to images. The text is missing from the question. The text on the picture is too small for some people to read. The text on the image cannot be indexed by search engines for future visitors. Also see [Why not upload images of code on SO when asking a question?](https://meta.stackoverflow.com/q/285551/608639) – jww Sep 22 '19 at 17:16

3 Answers3

1

You can use something like this :

ifconfig wlan0| awk '/inet /{print $2}'
ifconfig wlan0| grep -w "inet"|cut -d" " -f2
Pacifist
  • 3,025
  • 2
  • 12
  • 20
  • Ifconfig wlan0 will restrict your output to wlan0 only. Then awk command will fetch the line having inet in it. After that we are printing second element which is the needed IP address. Same is true for other command where we are using grep to fetch the line having inet in it and cut to print the second element. – Pacifist Sep 22 '19 at 08:47
  • @zaid try to break it and run. Like first-run till grep, don't include cut. That way you'll be able to debug it. It working for me though. Maybe we need to change it a little. – Pacifist Sep 22 '19 at 17:38
0

That exact CMD will be useful :

ifconfig wlan0 inet | grep inet | cut -d ' ' -f2
0

You can do it by only grep.

ifconfig wlan0 | grep -oE '\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}'
Yuji
  • 525
  • 2
  • 8