in reply to Re: Count occurrences and rename words in order
in thread Count occurrences and rename words in order

If the data is in a file (say logfile) a one-liner could be used.
$ perl -pe 's|(/\w+)|$1 . ++$counts{$1}|ge' logfile>countedlogfile $ cat logfile doc123/print doc456/read doc789/print doc145/print doc123/read $ cat countedlogfile doc123/print1 doc456/read1 doc789/print2 doc145/print3 doc123/read2

--

flounder

Replies are listed 'Best First'.
Re: Re^2: Count occurrences and rename words in order
by davorg (Chancellor) on Sep 18, 2002 at 16:33 UTC

    Yeah, that works. It's unclear what the original poster wanted to do for multiple lines. I assumed that the counts should be cleared. In which case you'd do something like this:

    $ perl -pe '%counts=();s|(/\w+)|$1 . ++$counts{$1}|ge' logfile>counted +logfile
    --
    <http://www.dave.org.uk>

    "The first rule of Perl club is you do not talk about Perl club."
    -- Chip Salzenberg