Skip to main content
Rollback to Revision 1
Source Link
RomanPerekhrest
  • 30.9k
  • 5
  • 47
  • 68

Awk solution:

ifconfig -a | awk ' NR==2 'NR==2{ sub(/^[^0-9]*/, "", $2); printf "IP=%s\n", $2; exit }' 

Sample output:

IP=10.0.2.15 

Awk solution:

ifconfig -a | awk ' NR==2 { sub(/^[^0-9]*/, "", $2); printf "IP=%s\n", $2; exit }' 

Sample output:

IP=10.0.2.15 

Awk solution:

ifconfig -a | awk 'NR==2{ sub(/^[^0-9]*/, "", $2); printf "IP=%s\n", $2; exit }' 

Sample output:

IP=10.0.2.15 
added 2 characters in body
Source Link
Rui F Ribeiro
  • 58k
  • 28
  • 156
  • 239

Awk solution:

ifconfig -a | awk 'NR==2' NR==2 { sub(/^[^0-9]*/, "", $2); printf "IP=%s\n", $2; exit }' 

Sample output:

IP=10.0.2.15 

Awk solution:

ifconfig -a | awk 'NR==2{ sub(/^[^0-9]*/, "", $2); printf "IP=%s\n", $2; exit }' 

Sample output:

IP=10.0.2.15 

Awk solution:

ifconfig -a | awk ' NR==2 { sub(/^[^0-9]*/, "", $2); printf "IP=%s\n", $2; exit }' 

Sample output:

IP=10.0.2.15 
Source Link
RomanPerekhrest
  • 30.9k
  • 5
  • 47
  • 68

Awk solution:

ifconfig -a | awk 'NR==2{ sub(/^[^0-9]*/, "", $2); printf "IP=%s\n", $2; exit }' 

Sample output:

IP=10.0.2.15