Sample Header Ad - 728x90

2 decimal increment in seq makes everything with 2 decimal

-3 votes
1 answer
672 views
I want to use this command in bash: datarange=$(seq 0.5 0.25 5.5) with output echo $datarange = 0.50 0.75 1.00 1.25 1.50 1.75 2.00 2.25 2.50 2.75 3.00 3.25 3.50 3.75 4.00 4.25 4.50 4.75 5.00 5.25 5.50 The problem is that this is for going into directories labeled D$i in a for loop where $datarange is called, but also where it's going to be for a qsub file it calls certain files numbered after a python numpy arange like this one: >>> import numpy as np >>> Steps=np.arange(0.5,5.75,0.25) >>> print(Steps) [0.5 0.75 1. 1.25 1.5 1.75 2. 2.25 2.5 2.75 3. 3.25 3.5 3.75 4. 4.25 4.5 4.75 5. 5.25 5.5 ] As the name needs a str I write this in Python filenamelist=[filenamer+str(Steps[j])+'.fdf' for j in range(len(Steps))] resulting in a file name like this one for example in the 2nd element (in python counting, whereas it's the 3rd one): filenamer1.0.fdf whereas for the 3rd (4th) would be: filenamer1.5.fdf and the next one: filenamer1.75.fdf As I need the D$i to be the same of the NumPy arange data, how can make that possible? If I use seq -f %.3g, it only keeps me the three more significant decimals but without adding a decimal. If I use seq -f %.3f, it would be the same result that if I won't use anything at all. May I need to stick to Python to change the directory and call over the program or is it solvable in Bash? EDIT: to clarify, i need help to do it in Bash And I dont want to elliminate all trailing zeros using %g because for example as you see in Python arange 1. and such stay in the strings as 1.0 and such, and so i can't read the files properly.
Asked by PARCB (1 rep)
Mar 24, 2021, 09:46 PM
Last activity: Mar 25, 2021, 02:35 PM