Need Help Parsing text
I am new to the site and need help parsing a file the file has a max of 2000 line and looks like this
i need to convert the above so i can insert it directly in to an sql database it need to look like this exactly not sure what is the best way to do it either somekind of script to convert the file or a sql script new to all this but getting there at the moment i have to do it manually which just takes me hours thanks in advance for your help
INSERT INTO `de_Coordonnee` (`ID`, `TYPE`, `POSIN`, `POSOUT`, `COORDET`, `COORDETOUT`, `NOTE`, `UTILISATEUR`, `udate`) VALUES
( , 1, '1006', '6473', '93-89-16', '94-21-33', '', 'Lee', 1283682460),
Forgot to add i would be willing to pay someone to do it
Don't bother; what you are asking is trivial. But we'll need some more information. What exactly is the format of the source file? What do each of those columns represent and how do they map to the resulting table? And we'll need to know what tools you have available. Perl? PHP? Or are you using a Windows box?
Originally Posted by lee1978
“The power of the Web is in its universality. Access by everyone regardless of disability is an essential aspect.”
—Tim Berners-Lee, W3C Director and inventor of the World Wide Web
Script for parsing text
Your specification example has some inconsistencies like how the data items in the input text file are to map onto the mysql table.
Below is some python code that does mostly what you want. I wrote it on the fly and it isn't tested and as is the way with code may need a little work Anyway it gives you a framework that you should be able to bang into what you want done.
I would have included the correct command construction and tested it if the example had been more clear. In Python indenting is important. The indent on this wiki isn't clear so you may need to check the indents
msqluser="whatever the msysql user is"
password="The user password...not secure but tough"
print "Input filei " +infileName+ " not found"
#Connect to the mysql database
db = MySQLdb.connect("localhost",mysqluser,passwd = password)
#Read each line of the data input file and split on the colon delimeters
for tableRec in paramfd.readlines():
for item in fields:
sqlcmd="insert into `de_Coordonnee` (`ID`, `TYPE`, `POSIN`, `POSOUT`, `COORDET`, `COORDETOUT`, `NOTE`, `UTILISATEUR`, `udate`) values"
# Execute the above command
Sorry the indent didn't come out Uhhh
Okay all lines after the first for command are indented once except
the line following the second for command is indented twice
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)