Sponsored Content
Top Forums Shell Programming and Scripting Help with printf in shell scripting Post 302666093 by ramman on Tuesday 3rd of July 2012 05:34:11 PM
Old 07-03-2012
Help with printf in shell scripting

Hi all I am using printf in my shell script to format my output.I am using the following code.

Code:
printf "|\tIP Address\t|\tModel Number\t|\tDOM/HW\t|\tSoftware Version\t|\n"		  
  
  printf "|\t%s\t|\t%s\t\t|\t%s\t|\t%s-%s\t\n" $encoder $modelno $type $sv1 $sv2 

  printf "|\tFPGA DATECODE\t|\tAX VERSION\t|\tUP TIME\t\n"

  printf "|\t%s\t|\t%s\t|\t%s days %s hours\t|\n" $fpgacode $axversion $edate1 $etime1


I need a output to be like following


Code:
|       IP Address      |       Model Number    |       DOM/HW  |       Software Version        |
|       10.77.168.58    |       SE-6601         |       DOM     |       0.0-0.120530_1325_RockMan8_root
|       FPGA DATECODE   |       AX VERSION      |       UP TIME
|       10251431        |       0x61210F0F      |       21 days 0 hours |


I give the IP address as command line argument and print the data.

When I give two IP address as input the output is messed up as follows:


Code:
|       04181458        |       0x61000035      |       20 days 1 hours |
|       10.77.168.54    |       SE-6601         |       DOM     |       4.1-2
|       10.77.168.58    |       SE-6601         |       DOM     |       0.0-0.120530_1325_RockMan8_root
|       10251431        |       0x61210F0F      |       21 days 0 hours |
|       FPGA DATECODE   |       AX VERSION      |       UP TIME
|       FPGA DATECODE   |       AX VERSION      |       UP TIME
|       IP Address      |       Model Number    |       DOM/HW  |       Software Version        |
|       IP Address      |       Model Number    |       DOM/HW  |       Software Version        |


I need the output to displayed neatly.

I feel the newline in the printf statement is executed before the variables are substituted.

Am I doing anything wrong?

Please suggest.Thanks.

Moderator's Comments:
Mod Comment Code tags for code please.
 

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

difference between AIX shell scripting and Unix shell scripting.

please give the difference between AIX shell scripting and Unix shell scripting. (2 Replies)
Discussion started by: haroonec
2 Replies

2. Shell Programming and Scripting

printf in bash shell not printing negative values

hi i am using printf in a script and it is not printing negative values..i have to use printf to get rid of the newline..here is my code: fin=`echo $a - $b | bc` printf "${fin}," >> test these statements are in a loop. here is what i get when i try to subtract 4 from 8: ./scr1: line... (2 Replies)
Discussion started by: npatwardhan
2 Replies

3. Shell Programming and Scripting

problem with printf in shell script

i have written small script as follows: name="hi hello" printf "%-20s" $name This gives me strange output. -20s format is applied on both word of string. i.e it displays both word hi and hello in space of 20 length. I want to display entire string "hi hello" in length of 20 space. plz... (2 Replies)
Discussion started by: admc123
2 Replies

4. Shell Programming and Scripting

Problem with printf in UNIX KSH shell

Hi ALL, I am using SunOS 5.9 and KSH(bin/ksh) The problem am facing is error message diaplyed on screen printf: 12099415.79 not completely converted printf: + expected numeric value printf: 11898578.29 not completely converted When i try printing with The output is... (6 Replies)
Discussion started by: selvankj
6 Replies

5. Shell Programming and Scripting

printf (awk,perl,shell) float rounding issue

Hi guys, could someone throw some light on the following behaviour of printf (I'll start with info about the system and the tool/shell/interpreter versions)?: $ uname -a Linux linux-86if.site 3.1.0-1.2-desktop #1 SMP PREEMPT Thu Nov 3 14:45:45 UTC 2011 (187dde0) x86_64 x86_64 x86_64... (9 Replies)
Discussion started by: elixir_sinari
9 Replies

6. Shell Programming and Scripting

Shell Printf command , a little more dynamic..

A big hello to everyone tagged to this site of knowledge . This is the first post of mine and I am looking forward to an enjoyable stint in this forum where I get to know a lot of new ideas and share whatever knowledge (its not much though :) ) I have acquired throughout my career so far with... (4 Replies)
Discussion started by: kumarjt
4 Replies

7. Shell Programming and Scripting

Need help in printf in shell script

My requirement is need to add spaces to the string with the dynamic value to printf... this is a part of shell script ..which i have , the length is not static ... length=15 value="1234567890" printf "%-"$length"s\n" "$value"; The result it is printing is ... i am not sure y it is... (19 Replies)
Discussion started by: greenworld123
19 Replies

8. UNIX for Beginners Questions & Answers

How to use printf to output a shell variable path?

So I created two shell variables: COLUMN1_HEADING, COLUMN2_HEADING. They have values: COLUMN1_HEADING="John" COLUMN2_HEADING="123456789" How would I use printf to get it to print an output like this: $COLUMN1_HEADING\t$COLUMN2_HEADING\nJohn\t123456789\n Thanks! (3 Replies)
Discussion started by: steezuschrist96
3 Replies
Mojo::DOM::HTML(3pm)					User Contributed Perl Documentation				      Mojo::DOM::HTML(3pm)

NAME
Mojo::DOM::HTML - HTML5/XML engine SYNOPSIS
use Mojo::DOM::HTML; # Turn HTML5 into DOM tree my $html = Mojo::DOM::HTML->new; $html->parse('<div><p id="a">A</p><p id="b">B</p></div>'); my $tree = $html->tree; DESCRIPTION
Mojo::DOM::HTML is the HTML5/XML engine used by Mojo::DOM. ATTRIBUTES
Mojo::DOM::HTML implements the following attributes. "charset" my $charset = $html->charset; $html = $html->charset('UTF-8'); Charset used for decoding and encoding HTML5/XML. "tree" my $tree = $html->tree; $html = $html->tree(['root', [qw(text lalala)]]); Document Object Model. "xml" my $xml = $html->xml; $html = $html->xml(1); Disable HTML5 semantics in parser and activate case sensitivity, defaults to auto detection based on processing instructions. METHODS
Mojo::DOM::HTML inherits all methods from Mojo::Base and implements the following new ones. "parse" $html = $html->parse('<foo bar="baz">test</foo>'); Parse HTML5/XML document. "render" my $xml = $html->render; Render DOM to XML. SEE ALSO
Mojolicious, Mojolicious::Guides, <http://mojolicio.us>. perl v5.14.2 2012-09-05 Mojo::DOM::HTML(3pm)
All times are GMT -4. The time now is 01:59 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy