View previous topic :: View next topic
|
Author |
Message |
Claes Norreen
Active User
Joined: 20 Dec 2005 Posts: 137 Location: Denmark
|
|
|
|
Hi,
I have the following request:
I have an array of NAMEs (about 70-80 different NAMEs), each NAME can be represented an unknown number of times. I need to add a sequence number to each row containing the same NAME, but the seqnum must only be incremented each 5th row. When a new NAME is encountered, the seqnum must be reset. The output should be a single file with the NAME and the seqnum. Example:
Code: |
NAME1 1
NAME1 1
NAME1 1
NAME1 1
NAME1 1
NAME1 2
NAME1 2
NAME1 2
NAME1 2
NAME1 2
NAME1 3
NAME1 3
NAME2 1
NAME2 1
NAME2 1
NAME2 1
NAME2 1
NAME2 2
NAME3 1
NAME3 1
NAME4 1
NAME4 1
NAME4 1
NAME4 1
NAME4 1
NAME4 2
NAME4 2
NAME4 2
|
How can I do this using ICETOOL? |
|
Back to top |
|
|
Claes Norreen
Active User
Joined: 20 Dec 2005 Posts: 137 Location: Denmark
|
|
|
|
Nevermind - I solved it myself now ;-)
If anyone want to know how, just say so - I'll be happy to post the solution here. |
|
Back to top |
|
|
William Thompson
Global Moderator
Joined: 18 Nov 2006 Posts: 3156 Location: Tucson AZ
|
|
|
|
Claes Norreen wrote: |
Nevermind - I solved it myself now ;-)
If anyone want to know how, just say so - I'll be happy to post the solution here. |
Please do, thank you...... |
|
Back to top |
|
|
Claes Norreen
Active User
Joined: 20 Dec 2005 Posts: 137 Location: Denmark
|
|
|
|
The trick is to use START and INCR of the SEQNUM keyword, and then cut the last digit:
Code: |
SORT FIELDS=(1,5,CH,A)
OUTREC OVERLAY=(7:SEQNUM,15,ZD,START=10,INCR=2,RESTART=(1,5))
OUTFIL FNAMES=OUT,OVERLAY=(21:X)
|
|
|
Back to top |
|
|
anshul_gugnani
New User
Joined: 02 Nov 2009 Posts: 73 Location: Mumbai
|
|
|
|
Hi,
Can you please explain how the above sort works - like what does START,INCR and RESTART works here.
Thanks. |
|
Back to top |
|
|
Claes Norreen
Active User
Joined: 20 Dec 2005 Posts: 137 Location: Denmark
|
|
|
|
Hi,
Given the input I posted, the SEQNUM,15,ZD adds a 15 digit sequence number it in position 7. The sequence number starts at 10 (START) and is incremented by 2 (INCR) for each record. However when the key (in position 1 to 5) breaks (RESTART), the sequence number is reset (to 10, which is the starting number in this case). After the OUTREC OVERLAY, this is how it looks:
Code: |
----+----1----+----2----+
NAME1 000000000000010
NAME1 000000000000012
NAME1 000000000000014
NAME1 000000000000016
NAME1 000000000000018
NAME1 000000000000020
NAME1 000000000000022
NAME1 000000000000024
NAME1 000000000000026
NAME1 000000000000028
NAME1 000000000000030
NAME1 000000000000032
NAME2 000000000000010
NAME2 000000000000012
NAME2 000000000000014
NAME2 000000000000016
NAME2 000000000000018
NAME2 000000000000020
NAME3 000000000000010
NAME3 000000000000012
NAME4 000000000000010
NAME4 000000000000012
NAME4 000000000000014
NAME4 000000000000016
NAME4 000000000000018
NAME4 000000000000020
NAME4 000000000000022
NAME4 000000000000024 |
The OUTFIL OVERLAY then clears position 21, that is, cuts the last digit of the sequence number, and you're done. :-)
/Claes |
|
Back to top |
|
|
anshul_gugnani
New User
Joined: 02 Nov 2009 Posts: 73 Location: Mumbai
|
|
|
|
Hi Claes,
Thanks for detailed explaination.
This is awesome. |
|
Back to top |
|
|
|