| import sys |
| |
| argv = sys.argv |
| |
| assert len(argv) > 2, "usage: ./script.py filename cell1 cell2 ..." |
| |
| filename = argv[1] |
| cells = argv[2:] |
| |
| with open(filename) as f: |
| content = f.readlines() |
| |
| prev_remove = False |
| remove = False |
| new_content = [] |
| for line in content: |
| if line.startswith('X'): |
| for cell in cells: |
| if cell in line: |
| remove = True |
| elif line.startswith('+') and prev_remove: |
| remove = True |
| |
| if not remove: |
| new_content.append(line) |
| else: |
| print("Removing:", line) |
| |
| prev_remove = remove |
| remove = False |
| |
| with open(filename, 'w') as f: |
| f.writelines(new_content) |