I want to use nl command to do numbering for lines. Is it possible to set line-increment in nl command to a float number.
I know that we cant use -i switch to set line-increment like this:
JavaScript
x
$ cat test | nl -i 2
1 #! /bin/bash
3 for dir in dir1 dir2
5 do
but it doesn’t work for float numbers like:
JavaScript
$ cat test | nl -i 0.1
nl: invalid line number increment: ‘0.1’
I want the output to be like this
JavaScript
1 #! /bin/bash
1.1 for dir in dir1 dir2
1.2 do
Advertisement
Answer
Could use awk instead
JavaScript
awk '{print 0.9+(x=x+.1) FS $0}' file
With padding (up to 99999 lines, for more add higher number in printf)
JavaScript
awk '{printf "%-7.1f%sn",0.9+(x=x+.1),$0}'