I have a bunch of files containing the exact same log message. One of them happens but as messages are identical I don’t known which one. What I want to do is append a number after all these messages to distinguish them.
Now usually when I have a bunch search and replace to perform I just write a quick perl one-liner like:
perl -pi -e 's/searched/replacement/g' *.c
But how can I insert a counter in replacement ?
You can use the
eregex modifier to append a running counter value to your replacement as:Demo: