Python Forum

Full Version: Compare 2 files
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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)
what have you tried so far?
Please post your code working or not.
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.