Sponsored Content
Top Forums Shell Programming and Scripting Displaying Number with printf Post 302166152 by Tytalus on Monday 11th of February 2008 06:14:28 AM
Old 02-11-2008
well, you can do it like this with sed:

Code:
#  echo 12345678 | sed -e :x -e 's/\([0-9][0-9]*\)\([0-9][0-9][0-9]\)/\1,\2/' -e 'tx'
12,345,678

 

10 More Discussions You Might Find Interesting

1. 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

2. Programming

printf

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

3. 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

4. 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

5. 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

6. 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

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

8. 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

9. 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

10. 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
explain_printf_or_die(3)				     Library Functions Manual					  explain_printf_or_die(3)

NAME
explain_printf_or_die - formatted output conversion and report errors SYNOPSIS
#include <libexplain/printf.h> int explain_printf_or_die(const char *format); int explain_printf_on_error(const char *format); DESCRIPTION
The explain_printf_or_die function is used to call the printf(3) system call. On failure an explanation will be printed to stderr, obtained from the explain_printf(3) function, and then the process terminates by calling exit(EXIT_FAILURE). The explain_printf_on_error function is used to call the printf(3) system call. On failure an explanation will be printed to stderr, obtained from the explain_printf(3) function, but still returns to the caller. format The format, exactly as to be passed to the printf(3) system call. RETURN VALUE
The explain_printf_or_die function only returns on success, see printf(3) for more information. On failure, prints an explanation and exits, it does not return. The explain_printf_on_error function always returns the value return by the wrapped printf(3) system call. EXAMPLE
The explain_printf_or_die function is intended to be used in a fashion similar to the following example: int result = explain_printf_or_die(format); SEE ALSO
printf(3) formatted output conversion explain_printf(3) explain printf(3) errors exit(2) terminate the calling process COPYRIGHT
libexplain version 0.52 Copyright (C) 2010 Peter Miller explain_printf_or_die(3)
All times are GMT -4. The time now is 09:27 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy