Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Compare 2 files
#1
What is the Script in Python to
Print Field = 2 of "File1.txt" and Field = 4 of "File2.txt"
When Field = 1 is "A4" of "File1.txt" is equal Field = 1 is "A4" of "File2.txt"

File 1

| A1| A| Ab| Abc| ABCD| ABCDE| ABCDEF|
| A2| Ab| Abc| ABCD| ABCDE| ABCDEF|
| A3| Abc| ABCD| ABCDE| ABCDEF|
| A4| ABCD| ABCDE| ABCDEF|

File 2

| A1| A| Ab| Abc| ABCD| ABCDE| ABCDEF|
| A2| A| Ab| Abc| ABCD| ABCDE| ABCDEF|
| A3| A| Ab| Abc| ABCD| ABCDE| ABCDEF|
| A4| A| Ab| Abc| ABCD| ABCDE| ABCDEF|

Answer - ABCD (File 1) and ABCD (File 2)
Reply
#2
what have you tried so far?
Please post your code working or not.
Reply
#3
Hi @tslavov ,
Welcome to the forum. The aim of this forum is to help people to learn Python. So no complete programs will be given. You have to produce a program and if it does not do what you expected, then we will help you.
I see you have to read two files. So the first task is: write a program to open both files and read them line by line. I suggest you use open() and readline() for this.
Please show us what you make of it.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Compare folder A and subfolder B and display files that are in folder A but not in su Melcu54 3 569 Jan-05-2024, 05:16 PM
Last Post: Pedroski55
  Compare fields from two csv files georgebijum 3 1,376 Apr-25-2022, 11:16 PM
Last Post: Pedroski55
  Compare filename with folder name and copy matching files into a particular folder shantanu97 2 4,510 Dec-18-2021, 09:32 PM
Last Post: Larz60+
  How can I compare Python XML-Files and add missing values from one to another kirat 2 2,701 Aug-30-2019, 12:17 PM
Last Post: perfringo
  Compare two large CSV files for a match Python_Newbie9 3 5,829 Apr-22-2019, 08:49 PM
Last Post: ichabod801
  Keyword compare in two files and output the results kotigasp 2 2,853 Jan-23-2018, 08:13 AM
Last Post: buran

Forum Jump:

User Panel Messages

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