{"id":26727,"date":"2022-04-01T00:19:55","date_gmt":"2022-03-31T18:49:55","guid":{"rendered":"https:\/\/python-programs.com\/?p=26727"},"modified":"2022-04-01T00:19:55","modified_gmt":"2022-03-31T18:49:55","slug":"how-to-find-unique-lines-from-two-text-txt-files-in-python","status":"publish","type":"post","link":"https:\/\/python-programs.com\/how-to-find-unique-lines-from-two-text-txt-files-in-python\/","title":{"rendered":"How to Find Unique Lines from two Text(.txt) Files in Python?"},"content":{"rendered":"

In this article, let us see\u00a0how to use Python to find only the unique lines in two text\u00a0files (.txt\u00a0files). We may also state that we will use Python to remove the lines that already exist in both of the text (.txt) files and place the new lines in another.txt file.<\/p>\n

Let us consider the below two text files as an example:<\/p>\n

demotextfile_1.txt:<\/strong><\/p>\n

hello this is Python-programs\r\ngood morning all<\/pre>\n

demotextfile_2.txt:<\/strong><\/p>\n

hello this is Python-programs\r\nAre you good at coding? \r\nThen give a start to it\r\nwelcome to the greatest python coding platform\r\ngood morning all<\/pre>\n

The output of our code must be as follows:<\/strong><\/p>\n

Are you good at coding? \r\nThen give a start to it\r\nwelcome to the greatest python coding platform<\/pre>\n

Finding Unique Lines from two Text(.txt) Files in Python<\/h2>\n

Approach:<\/strong><\/p>\n