Python Forum
Find lines from one file in another
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Find lines from one file in another
#7
I really appreciate your help! Smile

I see your point but your code does not have an "else" statement.
I need it, I need to process lines that do not match.
I can print lines that are matched. The iteration in Python is a horror story. Wall Wall Wall
I'd like to repeat, I do not have(by now) finding or matching lines, I have a problem printing those that do not match.
Here is a try 234 of the script:

fout = open ('C:/Scripts/sometext.txt','w')        

with open ('C:/Scripts/Python/CurMACs.txt','r') as cur_fl :        
    cur2 = cur_fl.readlines()
with open ('C:/Scripts/Python/Matched_MACs.txt','r') as m_file :     

    for m_line in m_file :
        m_line = m_line.rstrip()       
        sp_m_line = m_line.split(",")
        m_ltof = sp_m_line[0]+","+sp_m_line[1]  
        for cln2 in cur2 :
            cln2=cln2.rstrip()
        #    print ("Current Line file -->> ",cln2)
            if m_ltof in cln2 :
                #print ('Found Matched line -- ',cln2)
                new_n = cln2+","+"Online"
                print (new_n)
                fout.write(new_n+'\n')
                break

               # else :
               #     print ("OFFLINE !!!!!",cln2)
               #     #new_off= cln2+","+"OffLine"
               #     #fout.write(new_off+'\n')
               #     break
fout.close()
I tried to move the 'else' block all over the place wrote a countless number of snippets and still cannot print the lines that do not match..
Reply


Messages In This Thread
Find lines from one file in another - by tester_V - Nov-05-2020, 09:08 PM
RE: Find lines from one file in another - by tester_V - Nov-14-2020, 05:06 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  FileNotFoundError: [WinError 2] The system cannot find the file specified NewBiee 2 1,656 Jul-31-2023, 11:42 AM
Last Post: deanhystad
  Cannot find py credentials file standenman 5 1,724 Feb-25-2023, 08:30 PM
Last Post: Jeff900
  selenium can't find a file in my desk ? SouAmego22 0 775 Feb-14-2023, 03:21 PM
Last Post: SouAmego22
  Find (each) element from a list in a file tester_V 3 1,284 Nov-15-2022, 08:40 PM
Last Post: tester_V
  what will be the best way to find data in txt file? korenron 2 1,209 Jul-25-2022, 10:03 AM
Last Post: korenron
  Delete multiple lines from txt file Lky 6 2,390 Jul-10-2022, 12:09 PM
Last Post: jefsummers
  find some word in text list file and a bit change to them RolanRoll 3 1,586 Jun-27-2022, 01:36 AM
Last Post: RolanRoll
  failing to print not matched lines from second file tester_V 14 6,260 Apr-05-2022, 11:56 AM
Last Post: codinglearner
  Extracting Specific Lines from text file based on content. jokerfmj 8 3,142 Mar-28-2022, 03:38 PM
Last Post: snippsat
  Find and delete above a certain line in text file cubangt 12 3,637 Mar-18-2022, 07:49 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

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