in reply to To remove duplicate lines and add digits as per loop

You have interspersed your code with prose making it more difficult to download and analyse. Do not do that. Wrap your prose in <p> tags and your data and code in <code> tags instead, please.

Here is a one-liner which does what you want. Add -i to edit in-place (see perlrun)

perl -lpe '$s{$_}++; s/;$/_$s{$_};/' foo.txt

🦛

Replies are listed 'Best First'.
Re^2: To remove duplicate lines and add digits as per loop
by suvendra123 (Initiate) on Mar 16, 2021 at 02:13 UTC
    I don't want to change all lines , only to those lines where string is found

      There are so many ways to achieve that.

      • Change the pattern in the regular expression to match only those lines you want.
      • Make the substitution conditional on your pattern beforehand: /pat/ and s///
      • Don't munge any lines which don't match: next unless /pat/

      Pick one and implement it.


      🦛