I have a text file which a lot of random occurrences of the string @STRING\_A, and I would be interested in writing a short script which removes only some of them. Particularly one that scans the file and once it finds a line which starts with this string like

```
@STRING_A

```

then checks if 3 lines backwards there is another occurrence of a line starting with the same string, like

```
@STRING_A

@STRING_A

```

and if it happens, to delete the occurrence 3 lines backward. I was thinking about bash, but I do not know how to "go backwards" with it. So I am sure that this is not possible with bash. I also thought about python, but then I should store all information in memory in order to go backwards and then, for long files it would be unfeasible. 

What do you think? Is it possible to do it in bash or python?

Thanks