Jump to content

UltraEdit REGEX Question


pengu

Recommended Posts

I'm sorry I could not see any other places to ask this.  UltraEdit uses a similar method for REGEX for FIND & REPLACE (can also use Unix regex). http://www.ultraedit.com/support/tutorials_power_tips/ultraedit/regular_expressions.html

 

I just need some assistance, I have a data file with some information I want to insert into a database.

 

first_name,last_name,address1,city,postal,

D,Pearce,00 Changed St,PERTH,870,

M,Berghan,00 Changed St,PERTH,872,

 

I want to take the information from this file and change it to this.

 

insert into client_desc (first_name, last_name, Address1, City, Postal, Plate_Number, Email, Phone, Robot_id, description ) values('D','Pearce','00 Changed St','Perth','870','','','','','')

 

The order is not important I can change that myself with queries.

 

Once again I'm sorry if I've posted in the wrong section.

 

An example I came across, http://simonwillison.net/2003/Mar/23/ultraEditRegularExpressions/

Link to comment
Share on other sites

Do you really want to un-capitalize the "PERTH" into "Perth"? Is there any need to do this in UltraEdit, with a tiny PHP script you could read the comma-separated file into whatever format you like with whatever text transformations you like.

Link to comment
Share on other sites

Do you really want to un-capitalize the "PERTH" into "Perth"? Is there any need to do this in UltraEdit, with a tiny PHP script you could read the comma-separated file into whatever format you like with whatever text transformations you like.

 

No my post is obviously not clear enough.

 

I have this sort of data. 2000 lines or so, in a text document.

first_name,last_name,address1,city,postal,

D,Pearce,00 Changed St,PERTH,870,

M,Berghan,00 Changed St,PERTH,872,

 

I need to insert this information into a database, but due to microsoft being buggy I am unable to just do a straight import.

 

So I need to change all that information into the following. Having insert into client_desc (blablabla) at the start.  Then using all the information into variables and putting them between ' & ' and ending with a bracket.

 

insert into client_desc (first_name, last_name, Address1, City, Postal, Plate_Number, Email, Phone, Robot_id, description ) values('D','Pearce','00 Changed St','PERTH','870','','','','','')

 

Does this make sense, could a PHP script do that?  I really don't want to manually do this for 2000 lines of data lol.

Link to comment
Share on other sites

you mean like this ?

$result = preg_replace('/(.*?)\t(.*?)\t(.*?)\t(.*?)\t(.*)$/im', 'insert into client_desc (first_name, last_name, Address1, City, Postal, Plate_Number, Email, Phone, Robot_id, description ) values(\'\1\',\'\2\',\'\3\',\'\4\',\'\5\',\'\',\'\',\'\',\'\',\'\')', $data);

see attached

 

[attachment deleted by admin]

Link to comment
Share on other sites

<?php 
$YourFile = "Client_Desc.txt"; 
$handle = fopen($YourFile, 'r'); 
while (!feof($handle)) 
{ 
$Data = fgets($handle, 512); 
print "insert into client_desc (first_name, last_name, Address1, City, Postal, Plate_Number, Email, Phone, Robot_id, description ) values('" .$Data. "','','','','')"; 
print "<p>"; 
} 
fclose($handle); 
?> 

 

I have this so far, is it possible to put each variable or something into an array? (By variable I mean each peice of data, name , address etc)

 

EDIT:

Thanks Mad Techie, exactly what I was after!

Words can not explain the love I feel for you right now! :)

Link to comment
Share on other sites

I'm not being funny, but wouldn't this have been a lot easier by just using fgetcsv then imploding the array with quotes around it??

 

I saw fgetcsv() after, it probably would have done what I needed.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.