Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

printing line numbers with leading zeros... 1

Status
Not open for further replies.

jping45

Technical User
Aug 22, 2001
49
0
0
US
i have a file that contains 288 lines and I need to parse the data and grab various fields, (which is no problem), however I also need to add to the beginning of each line the line number with preceding zeros, (up to 4 characters) at the front of the line number.

EX:

T5041,66.3,11.3,21.9,0.5,23.8,70.9,30.1,6144.0
T5061,64.0,11.2,21.9,2.8,23.8,68.6,173.9,6144.0
T5081,64.0,11.3,21.9,2.8,23.8,68.6,172.8,6144.0
T5101,64.0,11.3,21.9,2.8,23.8,68.6,172.7,6144.0
.
.
.
T5121,63.9,11.2,21.9,2.9,23.8,68.5,179.1,6144.0
.
.
.
T5141,63.9,11.3,21.9,2.9,23.8,68.5,178.5,6144.0
T5161,64.3,11.3,21.9,2.6,23.8,68.9,157.6,6144.0


it should look like:
0001,66.3,11.3,21.9,0.5,23.8,70.9
0002,64.0,11.2,21.9,2.8,23.8,68.6
0003,64.0,11.3,21.9,2.8,23.8,68.6
0004,64.0,11.3,21.9,2.8,23.8,68.6
.
.
.
0056,63.9,11.2,21.9,2.9,23.8,68.5
.
.
.
0198,63.9,11.3,21.9,2.9,23.8,68.5
0199,64.3,11.3,21.9,2.6,23.8,68.9

Could someone point me in the right direction...


 
Code:
awk -F, '{printf "%04d,%s,%s,%s,%s,%s,%s\n",NR,$2,$3,$4,$5,$6,$7}' /path/to/input

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top