Welcome to the most active Linux Forum on the web.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 03-30-2010, 10:10 AM   #1
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: Bcast: Mask: inet6 addr: fe80::1031:3dff:fe01:55e1/64 Scope:Link

From the above line, I need the ip address like 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
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

Old 03-30-2010, 10:19 AM   #3
Senior Member
Registered: Jan 2010
Posts: 1,614

Rep: Reputation: 450Reputation: 450Reputation: 450Reputation: 450Reputation: 450
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
LQ Guru
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.9, Centos 7.3
Posts: 17,395

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

Original Poster
Rep: Reputation: 0

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


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 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 > Forums > Linux Forums > Linux - Newbie

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

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