Visit Jeremy's Blog.
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 11-05-2008, 08:32 PM   #1
LQ Newbie
Registered: Nov 2008
Posts: 9

Rep: Reputation: 0
gawk help needed.

Hi, i'm making right now a little perl script to connect to my LCDd server to display on an 20X4 LCD screen. I need to get my Local, External, and VPN ip adress.
I have found a script for the WAN one that is OK, but when i use my script to get the internal one, it seem to put a \n at the end, because i have a change line, so my lcd see the variable as a 2 line input and don't display it, i need to make it not put the last line change code. here is my internal ip script:

if [ -z "$1" ]; then 
	echo usage: $0 interface
IP=`/sbin/ifconfig $1 2> /dev/null|gawk '/inet addr/{print $2}'|gawk -F: '{print $2}'`

if [ "$IP" == "" ]; then
	echo "none"
	echo "$IP"
this is working fine, if i send this: eth0, i received this.
i set this as a variable, but in the variable i don't want the line change.

root@pbx:/usr/src $ eth0
root@pbx:/usr/src $
this script is my external ip script:

curl -s hxxp://www(dot)whatismyip(dot)com/automation/n09230945(dot)asp
and the output of this one is like that:
root@pbx:/usr/src $ $

and this is what i need, is there a way to have the same output from my first script?? thanx a lot!
Old 11-06-2008, 12:39 AM   #2
LQ Newbie
Registered: Oct 2007
Location: Pune
Distribution: RHEL, SOLARIS, SUSE
Posts: 18

Rep: Reputation: 1
i guess variable $IP has no new line in it.
"echo" adds the new line on the screen.

please try 'echo -n xxx':
if [ "$IP" == "" ]; then
echo -n "none"
echo -n "$IP"


Rohit Kalsarpe
Old 11-07-2008, 10:10 AM   #3
LQ Newbie
Registered: Nov 2008
Posts: 9

Original Poster
Rep: Reputation: 0
Thanx a lot it have work!!


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
gawk help.... visitnag Linux - Newbie 1 04-12-2008 11:55 AM
create a directory in gawk duparcmeur Linux - Newbie 6 04-03-2008 02:01 PM
where is curl and gawk ???????? bozart ROCK 11 10-23-2005 10:41 PM
gawk question luxpops Programming 1 09-12-2004 04:46 AM
FS=? in gawk realos Programming 2 05-28-2003 07:30 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:20 AM.

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