I started in Perl and I am reading the doc to learn things. My problem is simple, I have multiple files that I just need to manipulate, format to feed my MySQL database. I use MySQL 5.1, Toad Perl v4.1 & v5.10
This is one example among many other CSV file:
The desired result:Code:245362;77;77289;INR69907;Felt;799;20091102232406;;VEL;799;66;24; 243640;77;66017;INT81553;"Notebook";699;20091102232318;;VEL;699;66;24; 236958;77;08;DRT03286;bed;299;20091102231945;;VEL;299;66;15; 319771;77;79060;INA38898;Pen;399;20091102231902;;VEL;399;66;3; 319771;77;79060;BTQ38898;Pen;399;20091102231902;;VEL;399;66;24; 319250;77;13110;INJ40768;Mattresses;599;20091102231736;;VEL;599;66;24; 320343;77;21758;PRP31628;Mice;299;20091102231459;;VEL;299;66;24; 331379;77;27209;INT59377;Kit;299;20091102231319;;VEL;299;66;15; 314147;77;89301;BTQ12922;Scissors;0;20091102231248;;VEL;0;66;24; 334467;77;26234;TEL38873;Handkerchief;499;20091102231131;;VEL;499;66;24; 241749;77;37732;TEL90191;Eraser;699;20091102231104;;VEL;699;66;24;
it gives this:Code:insert into vod_billing values("236958","8","DRT03286","bed","299","20091102231945","15","DRT" ); insert into vod_billing values("241749","37732","TEL90191","Eraser","699","20091102231104","24","TEL" ); insert into vod_billing values("243640","66017","INT81553","Notebook","699","20091102232318","24","INT" ); insert into vod_billing values("245362","77289","INR69907","Felt","799","20091102232406","24","INT" ); insert into vod_billing values("314147","89301","BTQ12922","Scissors","0","20091102231248","24","BTQ" ); insert into vod_billing values("319250","13110","INJ40768","Mattresses","599","20091102231736","24","INT" ); insert into vod_billing values("319771","79060","BTQ38898","Pen","399","20091102231902","24","BTQ" ); insert into vod_billing values("319771","79060","INA38898","Pen","399","20091102231902","3","INT" ); insert into vod_billing values("320343","21758","PRP31628","Mice","299","20091102231459","24","PRP" ); insert into vod_billing values("331379","27209","INT59377","Kit","299","20091102231319","15","INT" ); insert into vod_billing values("334467","26234","TEL38873","Handkerchief","499","20091102231131","24","TEL" );
1.concatenate all *.csv* a directory into a single file
2.replace all characters "by anything (double quote)
3.Remove all duplicate lines
4.Sortby the first column
5. Remove all empty lines
6. The character is the delimiter column then delete column 2,8,9,10 & 11
7. To add last column in the first 3 characters of the column 3 (TEL, PRI etc ...)
8. On this last column, replace all INA INJ & Rs per INT
9. Insert before the line vod_billing insert into values ( "
10. To include end of line ");
11. To replace the delimiter, for ""
12. Rename the output file .sql
The ultimate goal would be to directly feed my MySQL database created with lines, but already such a script would be perfect.
I know it's a bit abused but probably simpler for a developer!
Bookmarks