LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
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, 10: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, 10:14 AM   #2
GrapefruiTgirl
LQ Guru
 
Registered: Dec 2006
Location: underground
Distribution: Slackware64
Posts: 7,594

Rep: Reputation: 556Reputation: 556Reputation: 556Reputation: 556Reputation: 556Reputation: 556
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, 10:19 AM   #3
crts
Senior Member
 
Registered: Jan 2010
Posts: 2,020

Rep: Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757
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, 07:03 PM   #4
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
Code:
echo $line |cut -d':' -f2|cut -d' ' -f1
 
1 members found this post helpful.
Old 03-31-2010, 01: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



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 08:41 PM
[SOLVED] SED - substitute a word only in a certain line carolflb Linux - Newbie 3 02-02-2010 09:30 AM
sed to delete a line for a word and line above cmontr Programming 11 07-03-2008 08:33 AM
sed/awk/grep for multiple line data hotrodmacman Programming 8 10-18-2007 11:06 AM
Need to strip words from front of line. sed/awk/grep? joadoor Linux - Software 6 08-28-2006 04:39 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 12:33 AM.

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
Open Source Consulting | Domain Registration