Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 Comapring two files
#1
Hi, i have 2 txt files which i want to compare.

File 1 has only dates.
File 2 has dates and some text.

All i want to do is out put in File 3 is all dates of File 1 and text against those dates in file 2.

can anyone help?
Quote
#2
What have you tried? We're happy to help you solve this yourself, but we get a lot of "do it for me"-looking posts even though we don't do people's work for them :)
Feel like you're not getting the answers you want? Checkout the help/rules for things like what to include/not include in a post, how to use code tags, how to ask smart questions, and more.

Pro-tip - there's an inverse correlation between the number of lines of code posted and my enthusiasm for helping with a question :)
Quote
#3
(Oct-02-2019, 09:39 PM)micseydel Wrote: What have you tried? We're happy to help you solve this yourself, but we get a lot of "do it for me"-looking posts even though we don't do people's work for them :)

Hi,

You are correct, so far what i did is i could open files and then use split to extract dates only. I cant figure our how to loop that for each line in file.

I would be great if you could or anyone else could point me to topic i need to read on or some url. As i am new to python so surely have not much experience in it.
Quote
#4
As a suggestion, look into Python's "re" module (regex). Then you could match line by line from both files.

See here for more suggestions.

Also here for how to iterate through a file.

import re

s1 = "2019-10-03 text in the source file"
s2 = "2019-10-03 text from the file to be searched"

matches = re.search("^(\d{4}-\d{1,2}-\d{1,2})(.*)$", s1)
print(matches.group(1))

# Then use an if in
if matches.group(1) in s2:
    matches = re.search("^(\d{4}-\d{1,2}-\d{1,2})(.*)$", s2)
    print(matches.group(2))
Quote
#5
Hi thanks for reply.

I used panda and numpy. IT works fine with small data but when i use my full file it does not work.
There are some column issues there but data is over thousand of rows so cant filter where it is messing up/
Quote
#6
(Oct-03-2019, 01:58 PM)usman88 Wrote: Hi thanks for reply.

I used panda and numpy. IT works fine with small data but when i use my full file it does not work.
There are some column issues there but data is over thousand of rows so cant filter where it is messing up/

Post your code so we can take a look :)
Quote
#7
hi sorry for late reply. i got that done this python and SQL. I would go for SQL as it helps me better for future purposes and data manipulation.
Quote
#8
If the dates are formatted the same way in both files it's quite easy using dictionaries.

Make from a second file a dictionary with the dates as a key and the text as a value. Then you can get the dates from the first file and use each of it as a key to the dictionary and print the item. If there is no such a key, no match.
burningkrome likes this post
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Quote

Top Page

Forum Jump:


Users browsing this thread: 1 Guest(s)