Displaying Number with printf

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Displaying Number with printf
# 8  
Old 02-12-2008

The solution posted by fpmurphy worked in the Linux I use:
#!/bin/bash -

# @(#) s1       Demonstrate feature.

echo "(Versions displayed with local utility \"version\")"
version >/dev/null 2>&1 && version =o $(_eat $0 $1) awk

cat >$FILE <<'EOF'
BEGIN { printf "%'d\n", 1234567 }

echo " awk script:"
cat $FILE

echo " Results with LC_ALL=C:"
LC_ALL=C gawk -f $FILE

echo " Results with LC_ALL=en_US.UTF-8:"
LC_ALL=en_US.UTF-8 gawk -f $FILE

exit 0

% ./s1
(Versions displayed with local utility "version")
Linux 2.6.11-x1
GNU bash 2.05b.0
GNU Awk 3.1.4

 awk script:
BEGIN { printf "%'d\n", 1234567 }

 Results with LC_ALL=C:

 Results with LC_ALL=en_US.UTF-8:

Best wishes ... cheers, drl
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Printf() not displaying as it should.

Hi, I have some code. Everything works as it should, but, when I call view_all_contacts() to print the data, each line doesn't line up as it should. I get tab keys between each line. The problem code is this: printf("\n\eHere is the rest of the code: void add_contact();... (5 Replies)
Discussion started by: ignatius
5 Replies

2. Shell Programming and Scripting

Adding user name to file, and then displaying new line number

Hi all - I'm completely stumped by a script I'm working on... The short version is I have a file called 'lookup' and in it are hundreds of names (first and last). I have a script that basically allows the user to enter a name, and what I need to have happen is something like this: Record... (8 Replies)
Discussion started by: sabster
8 Replies

3. Shell Programming and Scripting

Not able to sort two fields and printf not displaying the correct values

Not able to sorting two fileds resolved printf issue 01-1000/9|JAN 01-0000/6|MAN 01-1010/2|JAN 01-1010/2|JAN 01-1010/2|JAN 01-1000/9|JAN 01-1000/9|JAN 01-1000/9|SAA 01-1000/9|SAA 01-0000/6|SAN 01-0000/6|SAN 1.sort -t'|' -k1,1n -k2,2 file (3 Replies)
Discussion started by: kalia4u
3 Replies

4. Shell Programming and Scripting

Displaying a number in binary using perl

printf FH2" 3'b%b : begin\n",$i; where i is an integer in the loop is displaying 3'b1 : begin expected output was 3'b001 : begin (1 Reply)
Discussion started by: dll_fpga
1 Replies

5. Shell Programming and Scripting

Displaying lines of a file which have the highest number?

Hello Wondering if anybody may be able to advise on how I can filter the contents of the following file: <object_name>-<version> <Instance> GM_GUI_code.fmb-4 1 GM_GUI_code.fmb-5 1 GM_GUI_code.fmx-4 ... (7 Replies)
Discussion started by: Glyn_Mo
7 Replies

6. Shell Programming and Scripting

AWK: formating number without printf

Hello, I wrote a script that does lot of things, and I would like to change the format of a number but without printing it now (so I don't want to use printf as it will print the value immediately). Schematically here is what I have: awk 'BEGIN{number=0.01234567} $1==$2{$3=number}... (5 Replies)
Discussion started by: jolecanard
5 Replies

7. Shell Programming and Scripting

Displaying number of lines from file

Hi, I am using below command to display the number of line, but its returning no of lines along with file name. But i want only no of line in the variable p. Please help me on this? p=`wc -l "text file"` echo "$p" (6 Replies)
Discussion started by: shivanete
6 Replies

8. UNIX for Dummies Questions & Answers

Displaying Number with printf

I am trying to display a number with commas printf "%d\n" 323232 printf "%d\n" 1234567 I want the output to be: 323,232 1,234,567 I tried to change %d to other formats and could find the solution. any idea? (7 Replies)
Discussion started by: ynixon
7 Replies

9. Programming


What is the output of the following program considering an x86 based parameter passing sequence where stack grows towards lower memory addresses and that arguments are evaluated from right to left: int i=10; int f1() { static int i = 15; printf("f1:%d ", i); return i--; } main() {... (2 Replies)
Discussion started by: arunviswanath
2 Replies

10. Shell Programming and Scripting

printf returning unknown number

Hi, Can anybody tell me why this function returns 49? printf "%d\n" \'10 I don't understand what the \ and ' are there for? thanks!!! (1 Reply)
Discussion started by: m0nk3y
1 Replies
Login or Register to Ask a Question
SDL_JoystickOpen(3)						 SDL API Reference					       SDL_JoystickOpen(3)

SDL_JoystickOpen- Opens a joystick for use. SYNOPSIS
#include "SDL.h" SDL_Joystick *SDL_JoystickOpen(int index); DESCRIPTION
Opens a joystick for use within SDL. The index refers to the N'th joystick in the system. A joystick must be opened before it game be used. RETURN VALUE
Returns a SDL_Joystick structure on success. NULL on failure. EXAMPLES
SDL_Joystick *joy; // Check for joystick if(SDL_NumJoysticks()>0){ // Open joystick joy=SDL_JoystickOpen(0); if(joy) { printf("Opened Joystick 0 "); printf("Name: %s ", SDL_JoystickName(0)); printf("Number of Axes: %d ", SDL_JoystickNumAxes(joy)); printf("Number of Buttons: %d ", SDL_JoystickNumButtons(joy)); printf("Number of Balls: %d ", SDL_JoystickNumBalls(joy)); } else printf("Couldn't open Joystick 0 "); // Close if opened if(SDL_JoystickOpened(0)) SDL_JoystickClose(joy); } SEE ALSO
SDL_JoystickClose SDL
Tue 11 Sep 2001, 23:00 SDL_JoystickOpen(3)