Hi LMNmedchem,
Well done. I see no reason why the code you have will not meet your requirements.
You might want to consider this alternative that should be slightly faster (since it doesn't split or sort the input, and only looks at each field once):
Note that even if you don't want default filenames to be supplied if you invoke your script with less than two operands, you should still quote the filenames in the last line of your script in case someone invokes your script with a quoted operand containing an IFS character.
Thank you for the solution. I have not seen that syntax to supply a default argument. I have always just tested the value of the argument and set a value if there isn't one. Your suggestion is much preferable because it's not always easy to tell which argument is missing.
If I understand, you set the IO delimiters, and then start with the second row NR > 1. You assign the value of the third element to m, m = $3, and then compare each other element to m starting with element 4 up to the number of fields, for(i=4; i<=NF; i++).
The comparison, if($i && ($i < m || !m)), is a bit unclear to me. I would guess that if($1) is true if $i is not 0, like evaluating a boolean. The if(($i < m) keeps track of the lowest value but I don't know what the ||!m "or not m" does.
Also, is there any case where if(m) print $1, $2, m will not evaluate as true? I guess if $3=0 and all the rest of the elements are also 0 that statement will not be true. Is that how you trap against all 0 values in a row? If so, I would probably add an else there to print the id and name also with a user message to keep the output fully determined.
You haven't had to explicitly insert the tabs to the print statement since you specified the delimiter with OFS.
I have tried this with input where 0 is 0.0 and 0.0000 and it still works. How does that work with no explicit types?
Hi, guys,
today, I have copied a simple script which runs correctly on a computer to another one. But, the latter informs me:
Floating point exception!
@ ./command_module a b c
where command_module is the module compiled by myself.
So, I have fixed it by following steps:
1.... (5 Replies)
Hi,
I' using bash and I would like to use "bc" to compute the ratio of of two numbers and assign the ratio to a variable.
The numbers are in a file, e.g.
196.304492
615.348986
Any idea how to do it?
N.B. I cannot change the file to have 196.304492 / 615.348986 as the file is produced by... (14 Replies)
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)
Hello folks
I Hope everyone is fine. I am calculating number of bytes calculation from apache web log.
awk '{ sum += $10 } END { print sum }' /var/httpd/log/mydomain.log
7.45557e+09
it show above number, what should i do it sow number like 7455, i mean if after decimal point above 5 it... (5 Replies)
Hey,
I guess I am just to stupid and am not seeing the "wood for the trees", but I am always getting strange errors.
I want to create a mesh with coordinates like:
x y z
3.1 3.0 0.75 0 0 1
3.1 2.9 0.75 0 0 1
3.1 2.8 0.75 0 0 1
3.1 2.7 0.75 0 0 1
3.0 ... (10 Replies)
Hello Everyone,
I am currently working on a script to calculate optimal tcp window size
the formula that I am following is
2 x (bandwith speed /8 * Round Trip Time ) = x
This is what I have so far
#!/bin/bash
echo "Enter connection speed" << Get the speed of the Connection from... (3 Replies)
Heyas
I have a script (vhs - video handler script, using ffmpeg) to encode videos.
It also encodes a dvd, but until now just non-copy-protected ones, so i've tried to add/implement a vobcopy wrapper to be used by my script.
At first it looked quite fine, but when changing from the first VOB... (9 Replies)
Hello Guys,
I have a floating point number 1.14475E+15 I want to convert this number in to full number (Integer or Big integer). I tried couple of functions it did not work. When I use INT=${FLOAT/.*} I am getting value as 1. I don't want a truncated value
#!/bin/bash
#... (9 Replies)
I have the following code snippet in bash
if ]; then
minm=`echo "$diff" | bc`
fi
It works well for most of the cases. However lets say diff is -0.17 and minm is -0.0017. In such a case the comparison seems to fail. Is the correct way to compare a mixture of positive and... (12 Replies)