I'm having problems concatenating words of lines of 2 files, please

Viewed 21

i am doing concatenation of lines of 2 different files. When I do the tutorial with small data files it works fine but when I do it with few gigabyte files it gives the following error

root@vultr: ~/Downloads#python3 1.py 
Killed

Can you help me, thank you

1.py files are the command lines below. please edit the command for me, thank you very much

with open("file1.txt") as f1, open("file2.txt") as f2, open("output.txt", "w") as f3:
        file1_lines = f1.readlines()
        file2_lines = f2.readlines()
        
        for file1_line, file2_line in zip(file1_lines, file2_lines):
            file1_line = file1_line.strip(" \n")
            file2_line = file2_line.strip(" \n")
    
            # If either of the word is empty, do not write it. This could be modified as per the use case.
            if not file1_line or not file2_line:
                continue
    
            f3.write(f"{file1_line}{file2_line}\n") # Extra whitespace could be added as per the need.
0 Answers
Related