'program to Read content from 1 file and write string which is started from specific word and end with specific word into another file in python

Write a program to Read content from one file and write a string which is started from a specific word and ends with a different specific word into another file in python

I need to copy only string-like F,S,2,1380,980,400,45,45,45,E which is started from F and end with E in a new txt file from the logs file , Log file having 10k string like this F,S,4,3390,11980,60000,4500,65,15,25,E pls help me.



Solution 1:[1]

You can try this (if I understood the question correctly, this is the answer):

with open('input.txt', 'r') as in_file, open('output.txt', 'w') as out_file:
 for line in in_file.readlines():
  line = line.strip()
  if line[0] == 'F' and line[-1] == 'E':
   out_file.write(line + '\n')

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 ͔̲̲͛́̑̑̒̅ͅ ̴͈̮͉͉͛̀̒͋̒ ̲̎̅̽̑̀̿