Did you know LQ has a Linux Hardware Compatibility List?
Go Back > Forums > Linux Forums > Linux - General
User Name
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.


  Search this Thread
Old 01-23-2010, 08:54 PM   #1
Registered: May 2006
Location: Mt Umunhum, CA, USA
Distribution: Debian/ Fedora
Posts: 456

Rep: Reputation: 40
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.


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:
$ IP_Addr
eth0:None Done ppp0: Done
I'm running mawk 1.3.3 Nov 1996, Copyright (C) Michael D. Brennan

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

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

Original Poster
Rep: Reputation: 40
that did it

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


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 07:28 AM
AWK- processing data inside start/stop pairs but ignoring start/stop lines cliffoij Programming 2 10-15-2008 06:17 AM
printf doesn't work in awk MheAd Programming 4 09-24-2008 01:46 PM
shell command using awk fields inside awk one71 Programming 6 06-26-2008 04:11 PM
need help w/ awk & printf rickenbacherus Programming 3 05-13-2004 07:21 AM

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