04-14-2009
[bash]printf octal instead of decimal
Hello everybody,
I would like to understand why the printf function is returning me an octal value with this command :
printf %4.4d 0010 returns 0008
printf %4.4d 10 returns 0010
Thanks for help.
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
Dear all,
I have the following question. Let's say that I have the following script
#!/bin/bash
value=0.4987865
a=` printf "%6.2f" $value `
b=`echo $value + $value | bc -l`
echo $a
echo $b
exit
And the exit is:
0,00
.9975730
Thus, the problem is that the printf order does not... (2 Replies)
Discussion started by: josegr
2 Replies
2. Shell Programming and Scripting
Hi guys/gals i have a quick question. I am trying to read from a file and add the values up but the problem is the values are not integers their floats so i tried to used bc but failed epicly lol. Any tips would be great. Thanks
this is the code i have so far :
while read num
do
... (6 Replies)
Discussion started by: vb615
6 Replies
3. Homework & Coursework Questions
Hello all
I started computer science and C++ programming only 6 weeks ago with no prior knowledge. It's a great language, the only other one apart from English that I hope to speak fluently quite soon. I look forward to participating further on these forums, seeking answers and looking at previous... (3 Replies)
Discussion started by: qf_woodfox
3 Replies
4. Shell Programming and Scripting
I have searched and the answers I have found thus far have led me to this point, so I feel I am just about there.
I am trying to convert a column of hexadecimal to decimal values so that I can filter out via grep just the data I want. I was able to pull my original 3 character hex value and... (10 Replies)
Discussion started by: PCGameGuy
10 Replies
5. Shell Programming and Scripting
I need decimal comparing with if. Check if apache version is less than 2.2.17.
I tried this and not working.
#!/bin/bash
apachever=`/usr/local/apache/bin/httpd -v | head -1 | awk '{print $3}' |cut -d/ -f 2`
if ]; then
echo "Apache version less than 2.2.17"
else
... (7 Replies)
Discussion started by: anil510
7 Replies
6. UNIX for Dummies Questions & Answers
printf "%5.5\n" "1234567890"
will print 12345 . How do I get it to print
67890
Essentially, I just want the last 5 characters rather than the first 5. (4 Replies)
Discussion started by: lavender
4 Replies
7. Shell Programming and Scripting
I have a number in a bash variable n, and want to round it to 2 decimal places. How can I do that?
n=0.0867268
Need to have
num=0.09 (1 Reply)
Discussion started by: kristinu
1 Replies
8. Shell Programming and Scripting
Hi Experts,
Quick question:
I am trying to get the output with decimal and floating point but not working:
echo "20.03" | awk '{printf "%03d.2f\n" , $0 }'
020.2f
How to get the output as :
020.03
Thank you. (4 Replies)
Discussion started by: rveri
4 Replies
9. Shell Programming and Scripting
Hi,
I am facing some error while doing the comparision between 2 decimal values in bash. Pl help me out.
I have tried using below scripts. But its giving me error.
1)amt=12.3 opn_amt=12.5 var=$(awk 'BEGIN{ print "'$amt'"<"'$opn_amt'" }')
if ;then echo "correct" else echo "Wrong"... (3 Replies)
Discussion started by: Siba Tripathy
3 Replies
10. UNIX for Beginners Questions & Answers
Hello, this is my first time on the forum. I seem to not have the ability to start a new thread. However, I have a very simple question. I am trying to write a script I have to use printf to say "My name is myname (pulled from $USER) . it works with echo, but with printf the $USER... (2 Replies)
Discussion started by: sheltie042
2 Replies