The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
printing output more than 13 Krrishv Shell Programming and Scripting 2 01-22-2007 05:35 AM
Printing to a Savin - Size of output wrong h1timmboy AIX 2 02-28-2006 09:19 AM
Round off decimal number to 2 decimal places? Vozx Shell Programming and Scripting 1 12-07-2005 10:53 PM
Printing output to the monitor jyotipg Shell Programming and Scripting 2 06-22-2004 05:41 AM
Printing Problems in unix ... ( Bar-cdoe - Ip Printing) QuickSilver UNIX for Advanced & Expert Users 3 06-04-2002 10:48 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 05-28-2008
divzz divzz is offline
Registered User
  
 

Join Date: Mar 2008
Location: Bangalore
Posts: 20
Awking!! Printing decimal output is struck

Hi friends,

I have a small problem with AWK. I am not able to print decimal values! below is my code:

#! /bin/awk -f
awk BEGIN{printf("%d",123)}; -> This prints the integer properly.

x=111
awk BEGIN{printf("%d",x)}; -> This doesnt print!

Please help me solve this. It is printing 0 as output.
Thanks,
Divya
  #2 (permalink)  
Old 05-28-2008
ripat ripat is offline Forum Advisor  
Registered User
  
 

Join Date: Oct 2006
Location: Belgium
Posts: 438
Your didn't initialized the variable x within the awk instructions. Try:

Code:
 awk 'BEGIN{x=111; printf "%d", x}'
  #3 (permalink)  
Old 05-28-2008
penchal_boddu penchal_boddu is offline
Registered User
  
 

Join Date: Apr 2008
Location: Bangalore
Posts: 127
Hi,

If the value of x changes at the run time ,

u can use awk with -v option

awk -v val=$x 'BEGIN{printf("%d",val)}'

Thanks
Penchal
  #4 (permalink)  
Old 05-28-2008
divzz divzz is offline
Registered User
  
 

Join Date: Mar 2008
Location: Bangalore
Posts: 20
Quote:
Originally Posted by penchal_boddu View Post
Hi,

If the value of x changes at the run time ,

u can use awk with -v option

awk -v val=$x 'BEGIN{printf("%d",val)}'

Thanks
Penchal
Thanks Penchal.
  #5 (permalink)  
Old 05-28-2008
divzz divzz is offline
Registered User
  
 

Join Date: Mar 2008
Location: Bangalore
Posts: 20
Quote:
Originally Posted by ripat View Post
Your didn't initialized the variable x within the awk instructions. Try:

Code:
 awk 'BEGIN{x=111; printf "%d", x}'
Thanku very much, you are helpful
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 10:11 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0