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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Print record numbers within a group. 1

Status
Not open for further replies.

buckpasser

Technical User
Mar 10, 2005
24
US
I would like to add a record number field to a data file that gives/prints the record number within a group.

==============INPUT============

1st,6.0F,--->More data fields
1st,6.0F,--->More data fields
1st,6.0F,--->More data fields
1st,6.0F,--->More data fields
1st,6.0F,--->More data fields
1st,6.0F,--->More data fields
2nd,8.5F,--->More data fields
2nd,8.5F,--->More data fields
2nd,8.5F,--->More data fields
2nd,8.5F,--->More data fields
2nd,8.5F,--->More data fields
2nd,8.5F,--->More data fields
2nd,8.5F,--->More data fields
2nd,8.5F,--->More data fields
2nd,8.5F,--->More data fields
3rd,8.0F,--->More data fields
3rd,8.0F,--->More data fields
3rd,8.0F,--->More data fields
3rd,8.0F,--->More data fields
3rd,8.0F,--->More data fields
3rd,8.0F,--->More data fields
3rd,8.0F,--->More data fields
3rd,8.0F,--->More data fields
3rd,8.0F,--->More data fields
3rd,8.0F,--->More data fields
3rd,8.0F,--->More data fields
3rd,8.0F,--->More data fields
3rd,8.0F,--->More data fields
4th,6.0F,--->More data fields
4th,6.0F,--->More data fields
4th,6.0F,--->More data fields
4th,6.0F,--->More data fields
4th,6.0F,--->More data fields
4th,6.0F,--->More data fields

===============OUTPUT=================

1,1st,6.0F,--->More data fields
2,1st,6.0F,--->More data fields
3,1st,6.0F,--->More data fields
4,1st,6.0F,--->More data fields
5,1st,6.0F,--->More data fields
6,1st,6.0F,--->More data fields
1,2nd,8.5F,--->More data fields
2,2nd,8.5F,--->More data fields
3,2nd,8.5F,--->More data fields
4,2nd,8.5F,--->More data fields
5,2nd,8.5F,--->More data fields
6,2nd,8.5F,--->More data fields
7,2nd,8.5F,--->More data fields
8,2nd,8.5F,--->More data fields
9,2nd,8.5F,--->More data fields
1,3rd,8.0F,--->More data fields
2,3rd,8.0F,--->More data fields
3,3rd,8.0F,--->More data fields
4,3rd,8.0F,--->More data fields
5,3rd,8.0F,--->More data fields
6,3rd,8.0F,--->More data fields
7,3rd,8.0F,--->More data fields
8,3rd,8.0F,--->More data fields
9,3rd,8.0F,--->More data fields
10,3rd,8.0F,--->More data fields
11,3rd,8.0F,--->More data fields
12,3rd,8.0F,--->More data fields
13,3rd,8.0F,--->More data fields
1,4th,6.0F,--->More data fields
2,4th,6.0F,--->More data fields
3,4th,6.0F,--->More data fields
4,4th,6.0F,--->More data fields
5,4th,6.0F,--->More data fields
6,4th,6.0F,--->More data fields
 
Code:
BEGIN { FS="," }
$1 != old { count = 0 ; old = $1 }
{ print ++count "," $0 }

For an introduction to Awk, see faq271-5564.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top