Look for match in two files and print out in the first file - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Look for match in two files and print out in the first file (/thread-24770.html) |
Look for match in two files and print out in the first file - Batistuta - Mar-03-2020 Hi, I have two files and if Original.csv match in the 3 column it should then add the text Hello in the first file. If a value in Original.csv does not exists in Random.csv it should not add Hello reader1 = csv.reader(open('Original.csv', 'r'), delimiter=';') row1 = next(reader1) reader2 = csv.reader(open('Random.csv', 'r'), delimiter=';') row2 = next(reader2) if (row1[3] == row2[3]): print("Hello", row1) Orginal.csv contains: Quote:20200302075825;XAREAXAREAXAREAXARE5AXARE5AXA3REAXA;Alpha;46789877887;Direct;5;0;1113 Random.csv contains: 20200302075825;XAREAXAREAXAREAXARE5AXARE5AXA3REAXA;Test;46789877887;Direct;5;0;1113 20200302075825;XAREAXAREAXAREAXAREAXAREAX2AREAXA;Test;4644444444444;Direct;5;0;1113 20200302075825;1709A40CEC90001ABDD136E56F4983BF;Test;46700000922222;Direct;5;0;1113 So the output should be in Original.csv 20200302075825;XAREAXAREAXAREAXARE5AXARE5AXA3REAXA;Alpha;46789877887;Direct;5;0;1113;Yes 20200302075825;XAREAXAREAXAREAXAREAXAREAX2AREAXA;Alpha;4644444444444;Direct;5;0;1113;Yes 20200302075825;1709A40CEC90001ABDD136E56F4983BF;Alpha;46700000922222;Direct;5;0;1113;Yes 20200302075825;1709A40CEC90001ABDD136E56F4983BF;Alpha;46700000333333;Direct;5;0;1113 |