Help about using variables of float numbers in sed
Hi, I need to run a Fortran program which reads a input file with a fixed name many times, each time I need to change a number (real) in that input file, this is how I currently do it and I know it is not elegent at all:
I am looking for an elegent way, may be something like this:
The problem is in the line with sed: I don't know how to use the index "i", manipulate it like "$i/10.0" here, and use it in sed.
I know there must be some solution. Thank you very much for helps!
about the system: I am using Windows 10 (yes, I have to use windows!) with cygwin, the shell is bash.
thanks again!
Moderator's Comments:
Please use CODE tags as required by forum rules!
Last edited by RudiC; 12-01-2017 at 05:41 AM..
Reason: Added CODE tags.
As RudiC said, the bash shell doesn't do floating point calculations in arithmetic expansions. The Korn shell does (i.e., ksh), but I don't know if it is available on cygwin.
And, as RudiC implied, your sample changes do not match your script. Your sample script shows starting at 0.01, incrementing by .99, and then three increments of 1. If you are trying to replace the string 28.0 with a numbers starting with 0.0 and anding with 9.9 in steps of .1 you could also try:
if i want to display the contents of a file between say line number 3 and 10 then i use the following command
sed -n '3,10p' filename
if this 3 was contained in x and 10 was contained in y then how wud this command modified?
sed -n '$x,$yp' filename does not work..please advise (2 Replies)
Hi people :)
I'm learning shell scripting using bash and I want to generate 4 floating point number with 5 decimal places and write them to a file and a variable. I've done all this except the $RAMDOM enviroment variable does not generate a float number but a integrer.
I hope you could... (3 Replies)
Hi, i have a simple control like this:
if(sum>1.0)...
If i try to print sum i get 1.000000 but the check returns true. I think it depends on float precision. How can i modify the check?
thanks (1 Reply)
I wish to give line number from one point to another in sed command like this
sed -n 1,1000000p file1.txt >file2.txt
but variable line number $x,$x+100000 can i give it cos i tried and it was giving an error any suggestions?/
Thx in advance
AC (2 Replies)
Hi all,
I have doubt can array in a shell script can store floating point numbers. i have tired. but i unable to work it out.
Please help me regarding this
Thank U
Naree (1 Reply)
Good morning,
I'm testing the use of ceilf:
/*Filename: str.c*/
#include <stdio.h>
#include <math.h>
int main (void)
{
float ceilf(float x);
int dev=3, result=0;
float tmp = 3.444f;
printf("Result: %f\n",ceilf(tmp));
return 0;
} (1 Reply)
how to add 2 float values to each other?
i tried this and it doesnt work:
#!bin/bash
numone=1.234
numtwo=0.124
total=`expr $numone + $numtwo`
echo $total
thanks (5 Replies)