You can use cat -b or –number-nonblank options to number nonempty output lines.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
## Add data in your file echo -e "one\n\ntwo\nthree" > myfile ## Adds line no. infront of every lines, even empty ones cat -n myfile ## Returns ## 1 one ## 2 ## 3 two ## 4 three ## Adds line no. to only non-empty lines cat -b myfile ## Returns ## 1 one ## ## 2 two ## 3 three ## Same as cat -b myfile cat -nb myfile ## Returns ## 1 one ## ## 2 two ## 3 three |