LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Shell Script (https://www.linuxquestions.org/questions/linux-newbie-8/shell-script-656827/)

pangcake 07-19-2008 07:34 AM

Shell Script
 
> ifconfig
eth0 Link encap:Ethernet HWaddr 00:a0:d1:78:17:42
inet addr:10.34.119.12 Bcast:10.34.119.255
Mask:255.255.255.0
inet6 addr: fe80::2a0:d1ff:fe78:1742/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:3 errors:0 dropped:0 overruns:0 frame:0
TX packets:67 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:138 (138.0 B) TX bytes:7103 (6.9 KB)
Interrupt:17

eth1 Link encap:Ethernet HWaddr 00:1b:77:2a:11:99
inet6 addr: 2002:db2::21b:77ff:fe2a:1199/64
Scope:Global
inet6 addr: fe80::21b:77ff:fe2a:1199/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:3 errors:0 dropped:281 overruns:0 frame:0
TX packets:10 errors:0 dropped:1 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:2057 (2.0 KB) TX bytes:15461 (15.0 KB)
Interrupt:16 Base address:0x8000 Memory:f1000000-
f1000fff

if i wanna cut only eth1 part as shown below, which command should i use?

eth1 Link encap:Ethernet HWaddr 00:1b:77:2a:11:99
inet6 addr: 2002:db2::21b:77ff:fe2a:1199/64
Scope:Global
inet6 addr: fe80::21b:77ff:fe2a:1199/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:3 errors:0 dropped:281 overruns:0 frame:0
TX packets:10 errors:0 dropped:1 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:2057 (2.0 KB) TX bytes:15461 (15.0 KB)
Interrupt:16 Base address:0x8000 Memory:f1000000-
f1000fff

i've ever use grep but it prints only one line
so i dont know how can i get it.

Thanks

dv502 07-19-2008 08:03 AM

ifconfig | grep eth1


This will print all lines containing eth1

homey 07-19-2008 08:07 AM

Unless you're doing some kind of programming project, I would just use the command:
Code:

ifconfig eth1

matthewg42 07-19-2008 08:08 AM

Code:

ifconfig |sed -n -e '/^eth1/,/^$/ p'

matthewg42 07-19-2008 08:09 AM

homey: oh yeah... :D

dv502 07-19-2008 08:13 AM

Quote:

if i wanna cut only eth1 part as shown below, which command should i use?
Sorry, pangcake my mistake. I misunderstood.

sycamorex 07-19-2008 08:57 AM

Quote:

ifconig | sed -e '/./{H;$!d;}' -e 'x;/eth1/!d;'
will print only the eth1 paragraph

Quote:

ifconfig | sed -e '/./{H;$!d;}' -e 'x;/eth1/d;'
will print everything BUT the eth1 paragraph


All times are GMT -5. The time now is 02:51 PM.