Sponsored Content
Top Forums Shell Programming and Scripting printf in bash shell not printing negative values Post 302276807 by npatwardhan on Wednesday 14th of January 2009 03:51:59 PM
Old 01-14-2009
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:

Code:
fin[i]=`echo $a - $b | bc`
printf "${fin[i]}," >> test

these statements are in a loop. here is what i get when i try to subtract 4 from 8:
Code:
./scr1: line 58: printf: -4: invalid option
printf: usage: printf [-v var] format [arguments]
./scr1: line 58: printf: -4: invalid option
printf: usage: printf [-v var] format [arguments]
./scr1: line 58: printf: -4: invalid option
printf: usage: printf [-v var] format [arguments]
./scr1: line 58: printf: -4: invalid option
printf: usage: printf [-v var] format [arguments]
./scr1: line 58: printf: -4: invalid option
printf: usage: printf [-v var] format [arguments]

what can i do to get rid of this error?
 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Sorting positive and negative values

Hello, I have a list like this : 1 2 -4 0 -3 -7 5 6 etc. Is there a way to remove all the positive values and print only the negative values, without using grep, sed or awk? Thanks, Prasanna (4 Replies)
Discussion started by: prasanna1157
4 Replies

2. UNIX for Dummies Questions & Answers

Snmp Disk Problem = Negative Values

Ok, so i monitor disk space on remote machines using snmp. Works great for me. But whenever a particular partition happens to have Terabytes of data, snmp starts reporting negative values. Can someone please tell me how to get around this problem? The AllocationUnit is 512 bytes. Weird... (0 Replies)
Discussion started by: SkySmart
0 Replies

3. Shell Programming and Scripting

error- multiplying negative decimal values

a=10.02 pattern=-11.01 b=$(echo | awk '{ print $a*$pattern}') echo $b its not working even ALso tried `expr $a \* $pattern` No LUCK (3 Replies)
Discussion started by: saluja.deepak
3 Replies

4. Shell Programming and Scripting

replacing negative values in a column with zero

Hi, i need help on replacing negative values in a column with 0. any quick fix on this? thanks much. for instance, input: 1 2.3 -0.4 -25 12 13 45 -12 desired output 1 2.3 0 0 12 13 45 (4 Replies)
Discussion started by: ida1215
4 Replies

5. Shell Programming and Scripting

Shell : eliminating zero values and printing

I have a log file containing the below data and should have the output file as below. and the output file should not contain any 0 values. Eg. It should not contain 0000000:0000000 in it. input.txt Media200.5.5.1 00010003:065D1202 Media100.5.5.2 7,588,666,067,931,543... (6 Replies)
Discussion started by: scriptscript
6 Replies

6. Shell Programming and Scripting

Awk+colpos+negative if for 20 values

Hi All, i have 20 Obligors when ever i dont find all of them on particular row/line from each in put i need to print it in different file. using below command but it is not working please help at earliest. Steps: set -A FILENAME $( cat... (10 Replies)
Discussion started by: rajubollas
10 Replies

7. Shell Programming and Scripting

Conavert negative values to Zeros

Can anyone please assist me? Please find the attached input and output file for ur reference. a)Incase if i get negative value (ex:-000100) in the 11th column then i have to convert the value to 0000000(7 zeros-length is 7) and then print the entire record. b)Incase if there is no... (2 Replies)
Discussion started by: vinus
2 Replies

8. Shell Programming and Scripting

How to sum the value with negative values?

Hi Gurus, I have requirement need to sum the value, the logic is if the value is negative then time -1, I tried below two ways. one is failed, another one doesn't work. awk -F"," '{if($8< 0 $8*-1 else $8) sum+=$8}{print sum, $8} END{printf("%.2f\n",sum)}' awk -F","... (4 Replies)
Discussion started by: ken6503
4 Replies

9. Shell Programming and Scripting

Problem running plsql using printf command on bash shell

I am running plsql using printf on a shell, but i am getting some strange error, can someone point what exactly am i missing, $ echo $SHELL /bin/bash $ printf " > SET serveroutput ON trimspool on feed off echo off > declare > p_val number; > d_val varchar2(10); > begin > SELECT... (1 Reply)
Discussion started by: kamauv234
1 Replies
FMTCHECK(3)						   BSD Library Functions Manual 					       FMTCHECK(3)

NAME
fmtcheck -- sanitizes user-supplied printf(3)-style format string LIBRARY
Utility functions from BSD systems (libbsd, -lbsd) SYNOPSIS
#include <bsd/stdio.h> const char * fmtcheck(const char *fmt_suspect, const char *fmt_default); DESCRIPTION
The fmtcheck() scans fmt_suspect and fmt_default to determine if fmt_suspect will consume the same argument types as fmt_default and to ensure that fmt_suspect is a valid format string. The printf(3) family of functions cannot verify the types of arguments that they are passed at run-time. In some cases, like catgets(3), it is useful or necessary to use a user-supplied format string with no guarantee that the format string matches the specified arguments. The fmtcheck() was designed to be used in these cases, as in: printf(fmtcheck(user_format, standard_format), arg1, arg2); In the check, field widths, fillers, precisions, etc. are ignored (unless the field width or precision is an asterisk '*' instead of a digit string). Also, any text other than the format specifiers is completely ignored. RETURN VALUES
If fmt_suspect is a valid format and consumes the same argument types as fmt_default, then the fmtcheck() will return fmt_suspect. Other- wise, it will return fmt_default. SECURITY CONSIDERATIONS
Note that the formats may be quite different as long as they accept the same arguments. For example, "%p %o %30s %#llx %-10.*e %n" is com- patible with "This number %lu %d%% and string %s has %qd numbers and %.*g floats (%n)". However, "%o" is not equivalent to "%lx" because the first requires an integer and the second requires a long. SEE ALSO
printf(3) BUGS
The fmtcheck() function does not understand all of the conversions that printf(3) does. BSD
October 16, 2002 BSD
All times are GMT -4. The time now is 01:17 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy