Python Forum
failing to print not matched lines from second file
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
failing to print not matched lines from second file
#9
Using the example above

with open('f1.txt', 'r') as file:
    lines = set([line.strip().split(',')[3] for line in file])

with open('f2.txt', 'r') as file:
    for line in file:
        line = line.strip()
        if line.split(',')[3] not in lines:
            print(f'{line} NO MATCH')
Output:
03/28/2021,P,16,LINE1 NO MATCH 03/28/2021,P,9,LINE3 NO MATCH 03/28/2021,P,8,LINE5 NO MATCH 03/28/2021,S,95,LINE6 NO MATCH 03/28/2021,S,1,LINE7 NO MATCH 03/28/2021,P,46,LINE8 NO MATCH
tester_V likes this post
I welcome all feedback.
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags
Download my project scripts


Reply


Messages In This Thread
RE: failing to print not matched lines from second file - by menator01 - Mar-30-2021, 12:47 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [solved] how to delete the 10 first lines of an ascii file paul18fr 7 1,842 Aug-07-2024, 08:18 PM
Last Post: Gribouillis
  Print the next 3 lines knob 3 1,148 May-22-2024, 12:26 PM
Last Post: andraee
  Cannot get cmd to print Python file Schauster 11 3,200 May-16-2024, 04:40 PM
Last Post: xMaxrayx
  Failing to connect by 'net use' tester_V 1 1,074 Apr-20-2024, 06:31 AM
Last Post: tester_V
  Failing to print sorted files tester_V 4 2,592 Nov-12-2022, 06:49 PM
Last Post: tester_V
  Saving the print result in a text file Calli 8 4,144 Sep-25-2022, 06:38 PM
Last Post: snippsat
  Failing reading a file and cannot exit it... tester_V 8 3,399 Aug-19-2022, 10:27 PM
Last Post: tester_V
  Failing regex tester_V 3 2,364 Aug-16-2022, 03:53 PM
Last Post: deanhystad
  Delete multiple lines from txt file Lky 6 3,987 Jul-10-2022, 12:09 PM
Last Post: jefsummers
  Print to a New Line when Appending File DaveG 0 1,700 Mar-30-2022, 04:14 AM
Last Post: DaveG

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020