LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   awk printf ignoring '\n' (https://www.linuxquestions.org/questions/linux-general-1/awk-printf-ignoring-%5Cn-784298/)

MrUmunhum 01-23-2010 09:54 PM

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??

Valery Reznic 01-24-2010 01:43 AM

Try echo with quotes:
Code:

echo "${IP_Text}"

MrUmunhum 01-25-2010 03:00 PM

that did it
 
Quote:

Originally Posted by Valery Reznic (Post 3838319)
Try echo with quotes:
Code:

echo "${IP_Text}"

That works, thanks.


All times are GMT -5. The time now is 04:14 AM.