bc Questions
6
Solved
I have a backup script on my server which does cron jobs of backups, and sends me a summary of files backed up, including the size of the new backup file. As part of the script, I'd like to divide ...
14
Solved
I do something like the following in a Makefile:
echo "0.1 + 0.1" | bc
(in the real file the numbers are dynamic, of course)
It prints .2 but I want it to print 0.2.
I would like to do this wi...
8
Solved
6
As regards integer adding one-liners, several proposed shell scripting solutions exist;
however, on closer look at each of the solutions chosen, there are inherent limitations:
awk ones would cho...
4
Solved
I am learning bash scripting. While exploring the math functions i am came across a command which calculated the value of pi.
seq -f '4/%g' 1 2 99999 | paste -sd-+ | bc -l
Although i understand...
11
Solved
bc doesn't like numbers expressed in scientific notation (aka exponential notation).
$ echo "3.1e1*2" | bc -l
(standard_in) 1: parse error
but I need to use it to handle a few records that are e...
Intromit asked 14/10, 2012 at 13:19
6
Solved
How do I truncate a floating point number using bc
e.g if I do
echo '4.2-1.3' | bc
which outputs 2.9 how I get it to truncate/use floor to get 2
3
Solved
This outputs 101110
echo "obase=2; 46" | bc
How can I make it output 8 digits, like this? : 00101110
I learned the above usage of bc here: Bash shell Decimal to Binary base 2 conversion
...
Conscript asked 22/3, 2022 at 7:16
2
Solved
Based on the answer to this question, I would like to default scale = 2 every time I start bc from the command line (or from inside vim). However, man bc did not mention a .bcrc file, and when I ex...
Refuel asked 24/3, 2014 at 21:58
2
Solved
I'm simply trying to multiplying some float variables using bc:
#!/bin/bash
a=2.77 | bc
b=2.0 | bc
for cc in $(seq 0. 0.001 0.02)
do
c=${cc} | bc
d=$((a * b * c)) | bc
echo "$d" | bc
done
A...
7
Solved
I'm trying to convert a hex string to binary. I'm using:
echo "ibase=16; obase=2; $line" | BC_LINE_LENGTH=9999 bc
It is truncating the leading zeroes. That is, if the hex string is 4F, it is con...
4
Solved
I'm trying to convert a series of bytes from hex to bin using bash.
but I keep getting (seemingly random) "(standard_in) 1: syntax error" replies from the following code:
for j in c4 97 91 8c 85 8...
3
Solved
Jack 10
J 10
A 20
Lu cal 20
A bc U 20
I want to get the sum of these nums: 10+10+20+20+20 = 80
but I can't use cat input|cut -d " " -f 3 to get the num, how can I do it?
3
Solved
I want to compute an average with 3 decimal figures, rounded to nearest, using bc.
For example:
average of 3, 3 and 5 should yield 3.667
and
average of 3, 3 and 4 should yield 3.333
I tr...
3
Solved
$ bc
BC> ibase=2
BC> 110&101 // wanna get 100
(standar_in) 8: syntax error
Wikipedia informs that the ops are "|, & and ^". It may be that they work only in certain BC-types or I mi...
Sherborne asked 1/6, 2010 at 23:14
5
Solved
So I am trying to use bc to calculate some logarithms but I also need to use it to calculate the modulus for something. Whilst making my script, I launched bc to test it.
Without any flags, bc <...
3
Solved
I stumbled over a curious bug, I think:
I tried to read "512" as a number to base 6, and output it as base 16:
echo "ibase=6;obase=16;512" | bc
161
As you can see, the output is 161, but it s...
2
My program in Java connects to a Database (Oracle XE 11g) which contains many dates (date format of OracleXE is set to syyyy/mm/dd).
Doing a query in the database with negative dates (before Chri...
2
bc, a Linux command-line calculator, is proficient enough to calculate
3^2
9
Even a negative exponent doesn't confuse it:
3^-2
0.11111
Yet it fails when it encounters
9^0.5
Runtime warning (...
3
Solved
I have downloaded CygWin(32-bit) and installed (on Windows 7 32 bit System) today to run shell script but i found one problem that bc command isn't working.
I am getting error -bash: bc: command no...
4
Solved
I would like to reverse the operation performed by the following bash command:
$ echo $((62#a39qrT))
9207903953
i.e. convert decimal 9207903953 to base 62, keeping bash standard of {0..9},{a..z}...
Punch asked 23/1, 2013 at 2:55
1
I am using bc and scale for evaluating a expression however I want it to round up instead of round down. What is the simplest way to do this?
$ read exp
5+50*3/20 + (19*2)/7
$ echo "scale=3;...
Tearoom asked 24/5, 2016 at 3:35
4
Solved
Ok so this is a hackerrank problem (https://www.hackerrank.com/challenges/bash-tutorials---arithmetic-operations). Basically, input is an arithmetic expression and I'm supposed to print out formatt...
2
Solved
Is there a way to disable bc's feature of splitting long numbers into several lines, something like scale variable for controlling decimal places? Sure, I can use sed, but is there a bc way of doin...
Anticipative asked 30/7, 2015 at 19:22
3
Solved
i am trying to solve this bash script which reads an arithmetic expression from user and echoes it to the output screen with round up of 3 decimal places in the end.
sample input
5+50*3/20 + (19*...
Guienne asked 7/12, 2014 at 7:32
1 Next >
© 2022 - 2024 — McMap. All rights reserved.