I have a set of files that need to have a number assigned to $3 for
each record, but if the record has the same value in $2, the value in
$3 must stay the same also.
Here is what it should end up looking like:
06/04/2004|898|1|
06/04/2004|898|1|
06/04/2004|898|1|
06/04/2004|899|2|
06/04/2004|899|2|
06/04/2004|900|3|
06/04/2004|901|4|
06/04/2004|902|5|
06/05/2004|903|6|
06/05/2004|903|6|
06/05/2004|904|7|
06/05/2004|904|7|
06/05/2004|904|7|
I can reset the counter for each new $2, with:
BEGIN {FS="|"; OFS="|"; last="";}
{
if ($2 != last) { line = 0; last = $2; }
line++; $3 =line;
print $0
}
but I can't figure out how to keep it the same if the $2 is the same
as the previous one.
Can anyone help me?