LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
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, 08:54 PM   #1
MrUmunhum
Member
 
Registered: May 2006
Location: Mt Umunhum, CA, USA, Earth
Distribution: Debian/ Fedora/ Ubuntu/ Raspbian
Posts: 549

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.

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, 12:43 AM   #2
Valery Reznic
ELF Statifier author
 
Registered: Oct 2007
Posts: 676

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

Original Poster
Rep: Reputation: 40
that did it

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


Reply



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

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 05:43 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
Open Source Consulting | Domain Registration