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 ...
Yaron asked 22/2, 2013 at 2:21

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...
Chandrachandragupta asked 6/12, 2011 at 15:16

8

Solved

I want to calculate the log (base 10) of a number. How can I do this using bc?
Liberate asked 1/11, 2011 at 3:50

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...
Dagon asked 27/6, 2017 at 1:30

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...
Strohbehn asked 7/5, 2014 at 17:45

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
Decury asked 13/12, 2013 at 3:44

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...
Dudley asked 24/6, 2015 at 18:45

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...
Delinquent asked 28/9, 2012 at 4:19

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...
Dysthymia asked 20/6, 2012 at 13:9

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?
Boulanger asked 18/5, 2012 at 3:16

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...
Irenairene asked 11/11, 2014 at 9:4

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 &lt...
Corabelle asked 14/12, 2014 at 14:16

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...
Wetzell asked 27/3, 2012 at 12:50

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...
Statue asked 19/10, 2017 at 16:52

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 (...
Diaper asked 23/4, 2013 at 8:49

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...
Heterochromatin asked 20/8, 2016 at 13:9

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...
Sparrowgrass asked 2/10, 2014 at 19:36

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

© 2022 - 2024 — McMap. All rights reserved.