Skip to content
Advertisement

Enquote multiple text fields in CSV – Sublime Text 3

I have a CSV file containing info to be inserted in a database with SQL using insert similar to the below example:

INSERT INTO `Person`(`name`, `occupation`, `residence`, `comments`) VALUES
(GIBEL ΕΛΛΗ,NULL,NULL,NULL)

I want to separate the text values from the null values. Specifically, I want to enquote text values and leave null as it is. Is there a way to do this using Sublime Text 3? Please bear in mind that I am not familiar with regexp. Each field in my DB is either VARCHAR or TEXT.

Advertisement

Answer

Example you supplied

INSERT INTO `Person`(`name`, `occupation`, `residence`, `comments`) VALUES (GIBEL ΕΛΛΗ,NULL,NULL,NULL)

Activate RegEx in ST3 Find and Replace.

Find Value

(.*VALUES ()(.*)(,NULL,NULL,NULL))

Replace Value

$1"$2"$3

Apply Replace All

Result

INSERT INTO `Person`(`name`, `occupation`, `residence`, `comments`) VALUES ("GIBEL ΕΛΛΗ",NULL,NULL,NULL)
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement