I want to delete the duplicate lines of a text file only if the duplicate items are within 5 lines of each other.
For example :
Chapter 1.1
Overview
Figure 1
Figure 2
Overview <- This should be deleted (ie. within 5 lines of the previous instance)
Figure 3
Figure 4
...
(many lines in between)
Chapter 1.2
Overview <- This should not be deleted (ie. not within 5 lines of the previous instance)
I tried to use awk '!a[$0]++' but this will delete all the duplicates lines on the entire file. I also tried with a loop and sed -n "$startpoint,$endpoint p" file.txt | awk '!a[$0]++' but this actually creates new duplicates...
What other approaches can I try to remove the duplicates lines that are within 5 lines of each other?