Posted By

chrisaiv on 03/02/09


grep cut ifconfig

Versions (?)

Figure out your Internal / External Ip Address using Terminal

 / Published in: Bash


This example uses the 'ifconfig' but with a little bit of grep to weed out the crap

  1. #1. Use ifconfig and pipe ( | ) it into grep which will search for the 'inet' field
  2. #2. Pipe the data once again into grep and reverse the logic of the search (-v) to remove Using -v will match all the lines that do not match (aka loopback)
  3. #3. Use Cut to show the second field in the line, using spaces as a delimiter
  5. ifconfig | grep 'inet ' | grep -v | cut -d\ -f2

Report this snippet  

You need to login to post a comment.