LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 03-19-2009, 05:42 AM   #1
ravi_chobey
Member
 
Registered: Sep 2007
Location: Bangalore,India
Distribution: Fedora,Mandriva,Debian
Posts: 180

Rep: Reputation: 30
Thumbs up dispalying IP address using echo


Using these commands,i can display the IP address of my address:

ifconfig eth0 | grep "inet addr" | cut -d: -f 2

awk 'print $2'.

But i dont have awk in my embedded system,and i want 2 use "echo".

How i could dsiplay ip address.

Regards,
Ravi
 
Old 03-19-2009, 05:50 AM   #2
pwc101
Senior Member
 
Registered: Oct 2005
Location: UK
Distribution: Slackware
Posts: 1,847

Rep: Reputation: 128Reputation: 128
Perhaps if you don't have awk, you may have cut? It'll do something as simple as this without breaking a sweat.
 
Old 03-19-2009, 06:13 AM   #3
david1941
Member
 
Registered: May 2005
Location: St. Louis, MO
Distribution: CentOS6
Posts: 267

Rep: Reputation: 58
Just echo the output of your ifconfig line:

echo `ifconfig eth0 | grep "inet addr" | cut -d: -f 2`

Dave

Or, easier to see using this format (same command though)
echo $(ifconfig eth0 | grep "inet addr" | cut -d: -f 2)

and adding the other cut as pwc101 suggested to clean it up:
echo $(ifconfig eth0 | grep "inet addr" | cut -d: -f 2| cut -d\ -f 1)

Last edited by david1941; 03-19-2009 at 06:39 AM.
 
Old 03-19-2009, 06:40 AM   #4
ravi_chobey
Member
 
Registered: Sep 2007
Location: Bangalore,India
Distribution: Fedora,Mandriva,Debian
Posts: 180

Original Poster
Rep: Reputation: 30
i am getting my output as:
192.168.1.11 Mask.I dont want this mask field.I want to remove it,i have
tried various options,but not able to do so.

Please help.

Regards,
Ravi
 
Old 03-19-2009, 06:44 AM   #5
david1941
Member
 
Registered: May 2005
Location: St. Louis, MO
Distribution: CentOS6
Posts: 267

Rep: Reputation: 58
I'm sorry, I added pwc101's suggestion as an edit above and should have reposted.

echo $(ifconfig eth0 | grep "inet addr" | cut -d: -f 2| cut -d\ -f 1)

Dave
 
  


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
How do I echo a message to a terminal on another IP address fdvj Linux - Newbie 5 05-13-2013 08:04 AM
ls | echo, I got blank, why can't echo take the 2nd seat in a pipeline? elinuxqs Linux - Newbie 6 11-24-2006 08:25 AM
BASH: How to NOT echo to screen with "if echo $x | grep ".*"; then" eur0dad Programming 9 07-27-2006 02:14 PM
Kphone echo (echo echo) scabies Linux - Software 0 10-18-2004 02:59 PM
Echo /devPrinting doesn't work, echo /usb/lp0 works, Testpage works, Printing doesn't Hegemon Linux - General 3 08-15-2002 01:13 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 02:36 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