I don't understand the requirements. Do you want to remove all lines from a file that duplicate the contents of field 2 of the first six lines of your input file? Why do we need to remove field 1 of the first line in the file, but keep field 1 in the other six lines that are kept? Since field 2 in the third line in the file is a duplicate of field 2 in the sixth, tenth, and thirteenth lines of the input file, why shouldn't they all be removed?
Are you always only concerned about matching the first six lines, or are you trying to find the first set of n ilnes that are duplicated later in the file?
If the chosen lines at the start of the file are duplicated multiple times, do you only want to remove the first set of duplicated lines or do you want to remove every set of duplicated lines?
Hi MadeInGermany, thanks ;). My suggestion also only works on the last line, because of the $!d which stops executing the code for every line except the last one and reads the next line... The $ before the g is therefore not necessary: