my $last; my $i = 0; while (<IN>) { chomp; $i++ if (!defined($last) || $_ ne $last); $last = $_; print OUT ("$_ $i\n"); }
One liner:
perl -lpe "$i++ if ($_ ne $last); $last = $_; $_.=' '.$i;" inputfile > + outputfile
(Swap ' for " and vice-versa if you're not using Windows.)
Update: eek, that's what I get for not testing. Added the missing $last=$_.
In reply to Re: incrementing a column
by ikegami
in thread incrementing a column
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |