Is there a way to create a loop that will output number starting from 0.1 to 10.0
0.1
0.2
0.3
0.4
0.5
..
...
10.0
This is what i tried.
for i in {1..50}; do printf -v i '%02d' $i ; echo "$i"; done
That will print
01
02
03
..
..
50
How do i add a period in between the two numbers?
Try:
for i in {1..50}; do printf -v i '%0.1f' `echo "scale=1;$i/10" | bc`; echo $i; done
Jotne
4
#!/bin/bash
for i in {0..10}; do
for j in {0..9}; do
echo $i"."$j
done
done
---------- Post updated at 21:28 ---------- Previous update was at 20:45 ----------
#!/bin/sh
awk 'BEGIN { for(i=0;i<=10;i++) for(j=0;j<=9;j++) print i "." j }' | awk '!/0.0/'
Edit: removed the first 0.0
, starting from 0.1
to 10.0
as requested.
ctsgnb
5
man seq
$ seq -f %02.1f 0.1 0.1 10
$ seq -f %02.1f 0.1 0.1 10 | nawk 'NR<8||NR>92{print;next}!c++{print "..."}'
0,1
0,2
0,3
0,4
0,5
0,6
0,7
...
9,3
9,4
9,5
9,6
9,7
9,8
9,9
10,0
$
Yoda
6
echo 1 10 | awk ' { for (i=$1; i<=$NF; i++) printf("%.1f\n", i/10); } '
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
1.0
or just use ksh93:
$ for ((i=.1;i<=10;i+=.1)); do printf "%.1f\n" $i; done
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
1.0
...
9.9
10.0
echo {0..9}.{0..9} 10.0 | sed '1s!0.0 0.1!0.1!;s! !\n!g;N'
for i in {1..100}; do printf '%d.%d\n' $((i/10)) $((i%10)) ; done
for i in {1..100}; do echo "$((i/10)).$((i%10))" ; done
drl
10
Hi.
Command jot is available on some systems:
#!/usr/bin/env bash
# @(#) s1 Demonstrate seq-like command jot.
pe() { for _i;do printf "%s" "$_i";done; printf "\n"; }
pl() { pe;pe "-----" ;pe "$*"; }
db() { ( printf " db, ";for _i;do printf "%s" "$_i";done;printf "\n" ) >&2 ; }
db() { : ; }
C=$HOME/bin/context && [ -f $C ] && $C jot specimen
pe
jot 100 .1 10 |
specimen
exit 0
producing:
% ./s1
Environment: LC_ALL = C, LANG = C
(Versions displayed with local utility "version")
OS, ker|rel, machine: Linux, 2.6.26-2-amd64, x86_64
Distribution : Debian GNU/Linux 5.0.8 (lenny)
bash GNU bash 3.2.39
jot - ( /usr/bin/jot, 2009-06-09 )
specimen (local) 1.17
Edges: 5:0:5 of 100 lines in file "-"
0.1
0.2
0.3
0.4
0.5
---
9.6
9.7
9.8
9.9
10.0
Check your system repositories; install as necessary, then see man jot for details.
Best wishes ... cheers, drl