Linux԰̳'s Archiver

mgqw 2008-3-26 11:58

εõipַ

õIPַΪifconfigʾĶ̫ˣãʴʲô

dearvoid 2008-3-27 08:56

Լһ :)

mgqw 2008-3-27 08:59

my_ip="$(ip -f inet addr | grep global | awk '{print $2}' | awk -F/ '{print $1}')"

my_ip=`ip -f inet addr | grep global | awk '{print $2}' | awk -F/ '{print $1}'`

my_ip="$(ifconfig | awk '{if ( $1 == "inet" && $3 ~ /^Bcast/) print $2}' | awk -F: '{print $2}')"

dearvoid 2008-3-27 09:08

looks good
[font=Courier][code][dearvoid@LinuxEden:Forum ~/tmp] # ifconfig eth0
eth0      Link encap:Ethernet  HWaddr 00:0F:1F:5F:85:F4
          inet addr:192.168.3.38  Bcast:192.168.3.255  Mask:255.255.255.0
          inet6 addr: fe80::20f:1fff:fe5f:85f4/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:212309057 errors:0 dropped:0 overruns:0 frame:0
          TX packets:14458424 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:3564460945 (3.3 GiB)  TX bytes:2987854844 (2.7 GiB)
          Interrupt:201

[dearvoid@LinuxEden:Forum ~/tmp] # ifconfig eth0 | sed -n '/inet addr:/ { s/.*inet addr:\([0-9.]*\).*/\1/; p; q; }'
192.168.3.38
[dearvoid@LinuxEden:Forum ~/tmp] # bye
[/code][/font]

li-jiahuan 2008-3-27 09:13

[code]
[root@andLinux ~]# LANG=C ifconfig eth1 | awk '/inet addr:/ { print substr( $2, 6 ) }'
192.168.11.150
[/code]

òǿ
Ҫʹ grep xxx xxx | awk  xxx ÷:Q
awkģʽƥ仹Ǻܺõ

dearvoid 2008-3-27 09:24

[quote]ԭ [i]li-jiahuan[/i] 2008-3-27 09:13 [url=http://www.linuxeden.com/forum/redirect.php?goto=findpost&pid=606297&ptid=162654][img]http://www.linuxeden.com/forum/images/common/back.gif[/img][/url]

[root@andLinux ~]# LANG=C ifconfig eth1 | awk '/inet addr:/ { print substr( $2, 6 ) }'
192.168.11.150


òǿ
Ҫʹ grep xxx xxx | awk  xxx ÷:Q
awkģʽƥ仹Ǻܺõ [/quote]
Ϊ󲿷˸һ awk ǺԵʰ :)

twf_cc 2008-3-27 11:01

ѽo sed , awk ֻ grep , cut, tail   :lol
ip=$(ifconfig eth0 | grep -A1 eth0 | cut -d: -f2 | grep -E '[0-9]+\..*' | cut -d" " -f1)

ip=$(ifconfig eth0 | grep -A1 eth0 | cut -d: -f2 | tail -n1)
ip=${ip//[!0-9.]/}

dearvoid 2008-3-27 11:26

[quote]ԭ [i]twf_cc[/i] 2008-3-27 11:01 [url=http://www.linuxeden.com/forum/redirect.php?goto=findpost&pid=606310&ptid=162654][img]http://www.linuxeden.com/forum/images/common/back.gif[/img][/url]
ѽo sed , awk ֻ grep , cut, tail   :lol
ip=$(ifconfig eth0 | grep -A1 eth0 | cut -d: -f2 | grep -E '[0-9]+\..*' | cut -d" " -f1)

ip=$(ifconfig eth0 | grep -A1 eth ... [/quote]
оλҲк shell scripting :)

twf_cc 2008-3-27 12:14

ǵģmһcc Perl ruby , rg߀ shell   :lol
o sed , awk ķLZ ȥ˼· ,
'There is more than one way to do it' Larry Wall Perl
ԣshellҲѽ  :lol  
linux/Unix Сߺeõ  :lol

li-jiahuan 2008-3-28 12:33

ӭtwf_ccshell ֲ:D

e4twood 2008-3-28 15:54

hostname -i

ҳ: [1]

Powered by Discuz! Archiver 6.1.0  © 2001-2007 Comsenz Inc.