Hi.
Often one can use standard utilities to handle commonly-occurring issues. In this case:
nl (1) - number lines of files
As in this demo:
#!/usr/bin/env bash
# @(#) s1 Demonstrate line numbering utility nl
# Utility functions: print-as-echo, print-line-with-visual-space, debug.
# export PATH="/usr/local/bin:/usr/bin:/bin"
LC_ALL=C ; LANG=C ; export LC_ALL LANG
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 nl
FILE=${1-data1}
pl " Input data file $FILE:"
cat $FILE
pl " Results:"
nl -v1 -i1 -l1 -s, -w6 -nrz -hn -bt -fn $FILE
exit 0
producing:
$ ./s1
Environment: LC_ALL = C, LANG = C
(Versions displayed with local utility "version")
Linux 2.6.26-2-amd64
GNU bash 3.2.39
nl (GNU coreutils) 6.10
-----
Input data file data1:
500,Sourav ,kolkata ,8745775020,700091
505,ram,delhi ,9875645874,600032
510 ,madhu ,mumbai ,5698756430 ,500042
515 ,ramesh ,blore ,8769045601 ,400092
-----
Results:
000001,500,Sourav ,kolkata ,8745775020,700091
000002,505,ram,delhi ,9875645874,600032
000003,510 ,madhu ,mumbai ,5698756430 ,500042
000004,515 ,ramesh ,blore ,8769045601 ,400092
See man nl for details.
Best wishes ... cheers, drl