LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-30-2010, 11:10 AM   #1
nagendra
LQ Newbie
 
Registered: Mar 2010
Posts: 2

Rep: Reputation: 0
Question how to get a word from a line using sed or grep


Hi everyone,

I am struggling with a problem.

I am trying to get a word from a line using sed. Following is the line which I want to use.

inet addr:10.245.86.15 Bcast:10.245.87.255 Mask:255.255.254.0 inet6 addr: fe80::1031:3dff:fe01:55e1/64 Scope:Link

From the above line, I need the ip address like 10.245.86.15 only.

Can u help me in this regard and thanks in advance.

Thanks and Regards,
Nagendra Kumar Aluru
 
Old 03-30-2010, 11:14 AM   #2
GrapefruiTgirl
LQ Guru
 
Registered: Dec 2006
Location: underground
Distribution: Slackware64
Posts: 7,594

Rep: Reputation: 551Reputation: 551Reputation: 551Reputation: 551Reputation: 551Reputation: 551
Please show us some of the attempts you have made during your struggle; perhaps we can point out where the problem lies within your code.

And, welcome to LQ

Sasha
 
Old 03-30-2010, 11:19 AM   #3
crts
Senior Member
 
Registered: Jan 2010
Posts: 1,606

Rep: Reputation: 448Reputation: 448Reputation: 448Reputation: 448Reputation: 448
Code:
sed 's/inet addr:\([[:digit:]]\{,3\}\.[[:digit:]]\{,3\}\.[[:digit:]]\{,3\}\.[[:digit:]]\{,3\}\).*/\1/' data_file
This worked.
 
1 members found this post helpful.
Old 03-30-2010, 08:03 PM   #4
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,240

Rep: Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324
Code:
echo $line |cut -d':' -f2|cut -d' ' -f1
 
1 members found this post helpful.
Old 03-31-2010, 02:17 AM   #5
nagendra
LQ Newbie
 
Registered: Mar 2010
Posts: 2

Original Poster
Rep: Reputation: 0
Question

Hi GrapefruiTgirl,chrism01 and crts

Thank you very much for your good response.

I am very happy to join LQ.

Now I taken chrism01 code.

Actually I am trying to prepare a script that connects to the remote system through ssh and gets the ip address of the remote system.

I need this ip address to create a firewall rule on Amazon EC2 instances security group.

Since Amazon EC2 instance does not give us a private ip but it gives like domU-xx-xx-xx-xx-xx-xx.compute-1.interna1 which is not useful to set the security group in the CIDR format.

So I prepared the script which launches Amazon EC2 instances automatically and sets their private ip address to security group.
So only my instances can access to each other.

Is there a way to do my activity simply?

Thanks in advance.

Thanks and Regards,
Nagendra Kumar Aluru
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
sed append word at end of line if word is missing franjo124 Linux - Newbie 3 03-08-2012 09:41 PM
[SOLVED] SED - substitute a word only in a certain line carolflb Linux - Newbie 3 02-02-2010 10:30 AM
sed to delete a line for a word and line above cmontr Programming 11 07-03-2008 09:33 AM
sed/awk/grep for multiple line data hotrodmacman Programming 8 10-18-2007 12:06 PM
Need to strip words from front of line. sed/awk/grep? joadoor Linux - Software 6 08-28-2006 05:39 AM


All times are GMT -5. The time now is 04:22 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration