You can use awk like this for processing your file on row/col basis: awk -v n=2 '{for (i=1; i<=NF/2; i++) $i/=n} 1' file 4 1 4 5 3 6 8 8 ...

Not sure if it fits your needs but it looks more logical to do it this way: FILE.txt 0 4.053 8.879 15.651 19.684 21.853 yourscript.sh cat FILE.txt | while read start_time end_time; do if [ -z "$end_time" ]; then end_time='21.853' fi #echo "This is start: $start_time" #echo "This is end:...

Regardless of whether the value itself is a string or a number, you can force it to be passed as a string using proper quotes using strval() bcmul(strval($database_decimal_value) , '1', '10'); And yes, you can pass those values to MySQL without quotes and it will treat them as numbers...

The problem is that for consecutive minus operations you compute in the wrong direction. You compute from right to left whereas your need to computer from left to right. If you have on the stack the operants 12 3 2 0 - - - you compute effectively 12 - (3...

I don't know whether bc support such a behaviour but you could just replace echo $BIN with printf "%08d\n" "$BIN" ...

$RANDOM is, at most, 32767: RANDOM Each time this parameter is referenced, a random integer between 0 and 32767 is generated. The sequence of random numbers may be initialized by assigning a value to RANDOM. If RANDOM is unset, it loses its special properties, even if it is subsequently reset....

I think this does what you want. { echo "obase=2; ibase=16"; xxd -c 32 -u -p file.bin; } | bc It just feeds both the settings and the streamed file contents to bc with a brace list. The -u flag to xxd makes it output upper case hex letters....

That's because, from the manual: expr % expr The result of the expression is the "remainder" and it is com‐ puted in the following way. To compute a%b, first a/b is com‐ puted to scale digits. That result is used to compute a-(a/b)*b to the scale of the maximum of...

linux,bash,standard-deviation,bc

<<< needs to be parsed by the shell, which happens before parameter expansion. When you try to execute SD=`$CMD` the string in $CMD is not reparsed, so <<< is treated as a literal string and passed as an argument to bc. You need something like BC_EXPRESSION='scale=10; sqrt((0' for i in...

This calculates the value of π using Gregory–Leibniz series: seq -f '4/%g' 1 2 99999 generates the fractions: 4/1 4/3 4/5 4/7 4/9 4/11 4/13 4/15 4/17 4/19 The paste pipeline paste -sd-+ combines those with alternate delimiters - and +. Finally, bc -l performs the arithmetic to give the...

math,arithmetic-expressions,bc

The key here is to be sure to use printf with the formatting spec of "%.3f" and printf will take care of doing the rounding as you wish, as long as "scale=4" for bc. Here's a script that works: echo -e "please enter math to calculate: \c" read x printf...

bash,if-statement,comparison,bc

In bash, you need to be very careful about spacing. For example: if [ $(echo " 0.5 > $X " | bc -l )==1 ]; then echo grande fi Here, there are no spaces around the ==, so it'll be interpreted as: if [ 0==1 ]; then fi Believe it...

bc < gpay > tgpay When gpay ends, bc quits because gpay is stdin, and EOF means "quit reading and exit instead" to bc. Which is what your instructor probably wanted to have his students learn....

from the bc man page: expr ^ expr: The result of the expression is the value of the first raised to the second. The second expression must be an integer. but since if x = a^b, then ln(x) = ln(a^b) = b(ln(a)), we can see that x = exp(b(ln(a))), so...