LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices



Reply
 
Search this Thread
Old 01-23-2010, 09:54 PM   #1
MrUmunhum
Member
 
Registered: May 2006
Location: Mt Umunhum, CA, USA
Distribution: Debian/ Fedora
Posts: 435

Rep: Reputation: 33
awk printf ignoring '\n'


Hi group,
I just installed Debian and ran into this problem.

When I run this bash script that calls awk, all the output is on a single line.

Code:
#!/bin/bash

IP_Text=`/sbin/ifconfig |          \
  awk '{ ORS = "\n\n" }{           \
  if($0 ~ /Ethernet/ ||            \
     $0 ~ /Point-to-Point/ ) {     \
    printf("%s:", $1);             \
    Line=getline;                  \
    Line=$2;                       \
    if(Line ~ /addr/ ) {           \
      n=split(Line,Array,":");     \
      printf("%s\n\n",Array[2]); } \
    else {                         \
      printf("None\n\n"); }        \
print "Done\n"; } }'`

echo ${IP_Text}
The output looks like this:
Code:
$ IP_Addr
eth0:None Done ppp0:66.81.51.154 Done
I'm running mawk 1.3.3 Nov 1996, Copyright (C) Michael D. Brennan

Any ideas??
 
Old 01-24-2010, 01:43 AM   #2
Valery Reznic
ELF Statifier author
 
Registered: Oct 2007
Posts: 670

Rep: Reputation: 134Reputation: 134
Try echo with quotes:
Code:
echo "${IP_Text}"
 
Old 01-25-2010, 03:00 PM   #3
MrUmunhum
Member
 
Registered: May 2006
Location: Mt Umunhum, CA, USA
Distribution: Debian/ Fedora
Posts: 435

Original Poster
Rep: Reputation: 33
that did it

Quote:
Originally Posted by Valery Reznic View Post
Try echo with quotes:
Code:
echo "${IP_Text}"
That works, thanks.
 
  


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 On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
printf \b not working as expected in AWK Rockydell Programming 5 11-13-2009 08:28 AM
AWK- processing data inside start/stop pairs but ignoring start/stop lines cliffoij Programming 2 10-15-2008 07:17 AM
printf doesn't work in awk MheAd Programming 4 09-24-2008 02:46 PM
shell command using awk fields inside awk one71 Programming 6 06-26-2008 05:11 PM
need help w/ awk & printf rickenbacherus Programming 3 05-13-2004 08:21 AM


All times are GMT -5. The time now is 04:47 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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration