I have a file that contains duplicate patterns. I want to delete all the lines between these patterns only when there are duplicate patterns.
For example, if the input file is:
Pattern1=File1
cat
dog
PatternEnd1
blah
blah
Pattern1=File1
fish
dog
Pattern1End
blah
blah
Pattern1=File1
tiger
dog
Pattern1End
The output should be:
Pattern1=File1
cat
dog
PatternEnd1
blah
blah
blah
blah
I tried using sed and doing sed '/Pattern1=File1/,/PatternEnd1/d'
but it is deleting everything whenever the pattern matches. I want to delete everything between duplicate patterns while preserving the first occurrence.
I want to do this inside a Perl script.