fork(1) download
  1. import fileinput
  2. import re
  3. import sys
  4.  
  5.  
  6. def make_replace(index):
  7. def replace(m):
  8. nonlocal index
  9. s = m.group(1) + str(index)
  10. index += 1
  11. return s
  12. return replace
  13.  
  14. index = 2 # index to delete
  15. file = fileinput.input(inplace='--inplace' in sys.argv)
  16. for line in file:
  17. if line.startswith('1.' + str(index)):
  18. break
  19. print(line, end='')
  20.  
  21. replace = make_replace(index=index)
  22. for line in file:
  23. print(re.sub(r'(^1\.)\d+', replace, line), end='')
Success #stdin #stdout 0.04s 9580KB
stdin
1.1. Пункт первый, текст.
1.2. Пункт второй, который будет полностью удален.
1.3. Пункт третий, текст.
stdout
1.1. Пункт первый, текст.
1.2. Пункт третий, текст.