Read values from a file and post to database
Posted on 2012-08-16
I have multiple text files in a folder.
I want to read 5 text files at a time and copy their content (1 line at a time to a mysql database). If there are duplicate items in the various files, the count for the word should increase based on the number of instances that are found
Example of: ABC.txt with these values:
World Wide Web
Example of another file: DEF.txt with these values:
My database should look like:
item_name, count, last_updated_datetime
World Wide Web, 1, 2012-08-15 03:00:00
Bill Gates, 1, 2012-08-15 04:00:00
Internet Connect, 1, 2012-08-15 03:20:00
Beach, 2, 2012-08-15 03:00:00
Information Exchange, 2, 2012-08-15 03:30:00
Water Park, 1, 2012-08-15 03:00:00
Market Operator, 1, 2012-08-15 03:00:00
Genius, 1, 2012-08-15 03:00:00
Once the file has been parsed and the values have been inserted to the database, the file should then move to a different folder. This folder should be labeled with todays date "20120815"
Can you help me get started by giving me an example script on how to take care of this?