Advertisement
Guest User

Untitled

a guest
Feb 18th, 2020
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. import os
  2.  
  3. first_marker = '# Vlan'
  4. second_marker = '# '
  5. with open(r"C:\123\des.cfg", "r") as source:
  6. n = 0
  7. for line in source:
  8. n += 1
  9. if first_marker in line:
  10. n_first_m = n - 1
  11. source.close()
  12.  
  13.  
  14. source_2 = ''
  15. for linenum,line in enumerate(open(r"C:\123\des.cfg", "r")):
  16. if linenum>n_first_m:
  17. split_source = line.strip()
  18. source_2 = source_2 + split_source + "\n"
  19.  
  20.  
  21. with open(r"C:\123\buff.cfg", "w") as f2:
  22. f2.write(source_2)
  23. f2.close()
  24.  
  25. with open(r"C:\123\buff.cfg", "r") as source:
  26. nn = 0
  27. for line in source:
  28. nn += 1
  29. if second_marker in line:
  30. n_second_m = nn - 2
  31. break
  32. source.close()
  33.  
  34. source_3 = ''
  35. for linenum,line in enumerate(open(r"C:\123\buff.cfg", "r")):
  36. if linenum<n_second_m:
  37. split_source = line.strip()
  38. source_3 = source_3 + split_source + "\n"
  39.  
  40.  
  41. with open(r"C:\123\source.cfg", "w") as f3:
  42. f3.write(source_3)
  43. f3.close()
  44.  
  45. os.remove(r"C:\123\buff.cfg")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement