How to copy the content from one file to an output file ?

I have a file that looks as follows :
[13:55] Hi,
[14:01] hi
[14:01] GFGFsfsfsdsfds
[14:02] dsdsdsdsd
I use a pattern to delete all digits within the brackets including the brackets.
It should work with one file but i want to open the first file with the text, do the manipulation, and then copy the result to file 2 (which is currently empty).

Can you check the following code and advise what should i correct ?
(By the way , i’m working under Ubuntu Linux so i included the full path of the text files).

import re
file1 = open("/home/dror/Documents/1.txt","r")
file2 = open("/home/dror/Documents/2.txt","w")
b = [re.sub(r'\([^)]*\)','',data) for line in file1]

@drors53 Welcome to the forum.

You can use a Python context manager to achieve your goal. It will look something like this.

with open('file1.txt', 'r') as f1:
    text = f1.readlines()

with open('file2.txt', 'w') as f2:

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.