Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 07-04-2012
Registered User
 
Join Date: Apr 2011
Location: 64500 - france ( south-ouest )
Posts: 55
Thanks: 21
Thanked 1 Time in 1 Post
Extracting substring between pattern only one time

Hello

ifconfig return :

eth0 Link encap:Ethernet HWaddr 11:24:1D:C1:99:BA
inet addr:192.168.0.1 Bcast:192.168.0.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:37307 errors:0 dropped:0 overruns:0 frame:0
TX packets:27319 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:31305813 (29.8 Mb) TX bytes:2229012 (2.1 Mb)
Interrupt:43 Base address:0x4000

lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:164 errors:0 dropped:0 overruns:0 frame:0
TX packets:164 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:20420 (19.9 Kb) TX bytes:20420 (19.9 Kb)

I would like somethings like


Code:
ADRESSE=$(ifconfig | sed -n '/addr:/,/Bcast:/p')
echo $ADRESSE
192.168.0.1

Help would be appreciated
Sponsored Links
    #2  
Old 07-04-2012
Mead Rotor
 
Join Date: Aug 2005
Location: Saskatchewan
Posts: 16,407
Thanks: 492
Thanked 2,538 Times in 2,421 Posts

Code:
$ /sbin/ifconfig lan | awk '/inet addr:/ { print substr($2, 6)}'
192.168.0.126
$

The Following User Says Thank You to Corona688 For This Useful Post:
jcdole (07-05-2012)
Sponsored Links
    #3  
Old 07-05-2012
Registered User
 
Join Date: Apr 2011
Location: 64500 - france ( south-ouest )
Posts: 55
Thanks: 21
Thanked 1 Time in 1 Post
Quote:
Originally Posted by Corona688 View Post
Code:
$ /sbin/ifconfig lan | awk '/inet addr:/ { print substr($2, 6)}'
192.168.0.126
$

Great.

Thank you very much
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Extracting substring shyamu544 Shell Programming and Scripting 5 05-20-2011 08:03 PM
Extracting a substring from a string in unix arunkumarmc Shell Programming and Scripting 19 05-21-2010 08:32 AM
Extracting substring from string sdosanjh Shell Programming and Scripting 6 04-20-2010 12:28 AM
Extracting substring using ${var:start:len} Raamc UNIX for Dummies Questions & Answers 3 06-05-2009 02:37 AM
extracting substring from a file name adityamahi Shell Programming and Scripting 4 12-30-2008 10:07 AM



All times are GMT -4. The time now is 04:51 AM.