I have a file like below,Every Transaction have serveral Task,Every Task
Have different line.Now I only select every transaction first 2 Task。
how to achieve below desired result.
Thanks in advance。
You've over-engineered yours by trying to get a 1/2 answer, when LT 2 would do. With WHEN=GROUP you'd need to do that subtraction, so it basically does work.
magesh23586's solution works like this.
The first RESTART will get each entire key numbered from 1-N. Of these, 2-N are unimportant, it is the "1" marking the start of the groups which is important.
The second RESTART only operates on the "1"s, so the first "1" will get "1", the second "2", the others are then irrelevant.
Having only marked the first record of each group with the second RESTART, the WHEN=GROUP on OUTREC propagates that to all the records in the group, then the INCLUDE= can pick all the records marked with 1s or 2s.
The sequence numbers need to be large enough to cover the number of records within a group, else mayhem will, as usual, ensue.
If a SORT were required as well, things could be different (due to the use of OUTREC because WHEN=GROUP cannot follow WHEN=(logicalexpression)). Depends on the data and the actual requirement for that case.
Here's an alternate. Since the records which aren't wanted aren't wanted, you can destroy them (or a byte of them) to indicate they are not wanted.
This can also be applied to Rohit's solution which works even if a SORT is needed.