Hi All,
I have a file of decimal numbers,
cat file1.txt
1.1382666907
1.2603107334
1.6118799297
24.4995857056
494.7632588468
560.7633734425
.....
I want to see the output as only 7 digits after decimal
cat output.txt
1.1382667
1.2603107
1.6118799
24.4995857
494.7632589
560.7633734
...
Thanks in advance,
nawk '{printf("%.7f\n", $1)}' myFile
OR
nawk '{print $1+0}' OFMT='%.7f' myFile
1 Like
for line in $(cat file1.txt); do whole=$(echo $line | cut -d. -f1); fraction=$(echo $line | cut -d. -f2 | cut -c 1-7); echo "$whole.$fraction"; done
one more ..
$ while read i;do echo "scale=7;$i/1" | bc;done<infile
Move the pipe out of the loop, so you run bc once to process all the data instead of running bc 376 separate times to process 376 lines.
while read i;do echo "scale=7;$i/1" ; done<infile | bc