Transforming CSV into SQL with Notepad++












0















Suppose I have a CSV file like this:



1,"abc",,,,
2,"def",,,"ghi",
3,,"jkl",,,"mno"


Now I need to transform it in 3 steps:




  1. Replace all empty spaces with the String NULL

  2. Add at the beginning of each line the String VALUES (

  3. Add at the end of each line the string );


So that I have:



VALUES (1,"abc",NULL,NULL,NULL,NULL);
VALUES (2,"def",NULL,NULL,"ghi",NULL);
VALUES (3,NULL,"jkl",NULL,NULL,"mno");


I would like to use Notepad++ or something similar.



This is needed in order to transform the csv into a valid sql file.










share|improve this question

























  • You can do it by using "Replace" of Notepad++ with RegEx (regular expression)

    – duDE
    Sep 17 '15 at 13:53
















0















Suppose I have a CSV file like this:



1,"abc",,,,
2,"def",,,"ghi",
3,,"jkl",,,"mno"


Now I need to transform it in 3 steps:




  1. Replace all empty spaces with the String NULL

  2. Add at the beginning of each line the String VALUES (

  3. Add at the end of each line the string );


So that I have:



VALUES (1,"abc",NULL,NULL,NULL,NULL);
VALUES (2,"def",NULL,NULL,"ghi",NULL);
VALUES (3,NULL,"jkl",NULL,NULL,"mno");


I would like to use Notepad++ or something similar.



This is needed in order to transform the csv into a valid sql file.










share|improve this question

























  • You can do it by using "Replace" of Notepad++ with RegEx (regular expression)

    – duDE
    Sep 17 '15 at 13:53














0












0








0








Suppose I have a CSV file like this:



1,"abc",,,,
2,"def",,,"ghi",
3,,"jkl",,,"mno"


Now I need to transform it in 3 steps:




  1. Replace all empty spaces with the String NULL

  2. Add at the beginning of each line the String VALUES (

  3. Add at the end of each line the string );


So that I have:



VALUES (1,"abc",NULL,NULL,NULL,NULL);
VALUES (2,"def",NULL,NULL,"ghi",NULL);
VALUES (3,NULL,"jkl",NULL,NULL,"mno");


I would like to use Notepad++ or something similar.



This is needed in order to transform the csv into a valid sql file.










share|improve this question
















Suppose I have a CSV file like this:



1,"abc",,,,
2,"def",,,"ghi",
3,,"jkl",,,"mno"


Now I need to transform it in 3 steps:




  1. Replace all empty spaces with the String NULL

  2. Add at the beginning of each line the String VALUES (

  3. Add at the end of each line the string );


So that I have:



VALUES (1,"abc",NULL,NULL,NULL,NULL);
VALUES (2,"def",NULL,NULL,"ghi",NULL);
VALUES (3,NULL,"jkl",NULL,NULL,"mno");


I would like to use Notepad++ or something similar.



This is needed in order to transform the csv into a valid sql file.







notepad++ regex csv






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 14 at 8:27







user1170330

















asked Sep 17 '15 at 13:51









user1170330user1170330

1105




1105













  • You can do it by using "Replace" of Notepad++ with RegEx (regular expression)

    – duDE
    Sep 17 '15 at 13:53



















  • You can do it by using "Replace" of Notepad++ with RegEx (regular expression)

    – duDE
    Sep 17 '15 at 13:53

















You can do it by using "Replace" of Notepad++ with RegEx (regular expression)

– duDE
Sep 17 '15 at 13:53





You can do it by using "Replace" of Notepad++ with RegEx (regular expression)

– duDE
Sep 17 '15 at 13:53










1 Answer
1






active

oldest

votes


















2














I believe I got it down to two find/replace expressions.



Press Ctrl+H to bring up the Replace dialog.



1,"abc",,,,
2,"def",,,"ghi",
3,,"jkl",,,"mno"


Find what: ^([^,]*),([^,]*),([^,]*),([^,]*),([^,]*),([^,]*)$

Replace with: VALUES(NULL1,NULL2,NULL3,NULL4,NULL5,NULL6);



VALUES(NULL1,NULL"abc",NULL,NULL,NULL,NULL);
VALUES(NULL2,NULL"def",NULL,NULL,NULL"ghi",NULL);
VALUES(NULL3,NULL,NULL"jkl",NULL,NULL,NULL"mno");


Find what: NULL([^,)])

Replace with: 1



VALUES(1,"abc",NULL,NULL,NULL,NULL);
VALUES(2,"def",NULL,NULL,"ghi",NULL);
VALUES(3,NULL,"jkl",NULL,NULL,"mno");





share|improve this answer
























  • Looks good, +1 !

    – duDE
    Sep 17 '15 at 14:21






  • 2





    Looks OK, since it offers no explanation of what is going on, which may actually help the OP learn something. +0

    – Ƭᴇcʜιᴇ007
    Sep 17 '15 at 15:39






  • 1





    Basically adds Null after every comma. Then removes null wherever there is some value after it.

    – jitendragarg
    May 2 '16 at 6:03











Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "3"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f974353%2ftransforming-csv-into-sql-with-notepad%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









2














I believe I got it down to two find/replace expressions.



Press Ctrl+H to bring up the Replace dialog.



1,"abc",,,,
2,"def",,,"ghi",
3,,"jkl",,,"mno"


Find what: ^([^,]*),([^,]*),([^,]*),([^,]*),([^,]*),([^,]*)$

Replace with: VALUES(NULL1,NULL2,NULL3,NULL4,NULL5,NULL6);



VALUES(NULL1,NULL"abc",NULL,NULL,NULL,NULL);
VALUES(NULL2,NULL"def",NULL,NULL,NULL"ghi",NULL);
VALUES(NULL3,NULL,NULL"jkl",NULL,NULL,NULL"mno");


Find what: NULL([^,)])

Replace with: 1



VALUES(1,"abc",NULL,NULL,NULL,NULL);
VALUES(2,"def",NULL,NULL,"ghi",NULL);
VALUES(3,NULL,"jkl",NULL,NULL,"mno");





share|improve this answer
























  • Looks good, +1 !

    – duDE
    Sep 17 '15 at 14:21






  • 2





    Looks OK, since it offers no explanation of what is going on, which may actually help the OP learn something. +0

    – Ƭᴇcʜιᴇ007
    Sep 17 '15 at 15:39






  • 1





    Basically adds Null after every comma. Then removes null wherever there is some value after it.

    – jitendragarg
    May 2 '16 at 6:03
















2














I believe I got it down to two find/replace expressions.



Press Ctrl+H to bring up the Replace dialog.



1,"abc",,,,
2,"def",,,"ghi",
3,,"jkl",,,"mno"


Find what: ^([^,]*),([^,]*),([^,]*),([^,]*),([^,]*),([^,]*)$

Replace with: VALUES(NULL1,NULL2,NULL3,NULL4,NULL5,NULL6);



VALUES(NULL1,NULL"abc",NULL,NULL,NULL,NULL);
VALUES(NULL2,NULL"def",NULL,NULL,NULL"ghi",NULL);
VALUES(NULL3,NULL,NULL"jkl",NULL,NULL,NULL"mno");


Find what: NULL([^,)])

Replace with: 1



VALUES(1,"abc",NULL,NULL,NULL,NULL);
VALUES(2,"def",NULL,NULL,"ghi",NULL);
VALUES(3,NULL,"jkl",NULL,NULL,"mno");





share|improve this answer
























  • Looks good, +1 !

    – duDE
    Sep 17 '15 at 14:21






  • 2





    Looks OK, since it offers no explanation of what is going on, which may actually help the OP learn something. +0

    – Ƭᴇcʜιᴇ007
    Sep 17 '15 at 15:39






  • 1





    Basically adds Null after every comma. Then removes null wherever there is some value after it.

    – jitendragarg
    May 2 '16 at 6:03














2












2








2







I believe I got it down to two find/replace expressions.



Press Ctrl+H to bring up the Replace dialog.



1,"abc",,,,
2,"def",,,"ghi",
3,,"jkl",,,"mno"


Find what: ^([^,]*),([^,]*),([^,]*),([^,]*),([^,]*),([^,]*)$

Replace with: VALUES(NULL1,NULL2,NULL3,NULL4,NULL5,NULL6);



VALUES(NULL1,NULL"abc",NULL,NULL,NULL,NULL);
VALUES(NULL2,NULL"def",NULL,NULL,NULL"ghi",NULL);
VALUES(NULL3,NULL,NULL"jkl",NULL,NULL,NULL"mno");


Find what: NULL([^,)])

Replace with: 1



VALUES(1,"abc",NULL,NULL,NULL,NULL);
VALUES(2,"def",NULL,NULL,"ghi",NULL);
VALUES(3,NULL,"jkl",NULL,NULL,"mno");





share|improve this answer













I believe I got it down to two find/replace expressions.



Press Ctrl+H to bring up the Replace dialog.



1,"abc",,,,
2,"def",,,"ghi",
3,,"jkl",,,"mno"


Find what: ^([^,]*),([^,]*),([^,]*),([^,]*),([^,]*),([^,]*)$

Replace with: VALUES(NULL1,NULL2,NULL3,NULL4,NULL5,NULL6);



VALUES(NULL1,NULL"abc",NULL,NULL,NULL,NULL);
VALUES(NULL2,NULL"def",NULL,NULL,NULL"ghi",NULL);
VALUES(NULL3,NULL,NULL"jkl",NULL,NULL,NULL"mno");


Find what: NULL([^,)])

Replace with: 1



VALUES(1,"abc",NULL,NULL,NULL,NULL);
VALUES(2,"def",NULL,NULL,"ghi",NULL);
VALUES(3,NULL,"jkl",NULL,NULL,"mno");






share|improve this answer












share|improve this answer



share|improve this answer










answered Sep 17 '15 at 14:15









StevenSteven

23.4k1076109




23.4k1076109













  • Looks good, +1 !

    – duDE
    Sep 17 '15 at 14:21






  • 2





    Looks OK, since it offers no explanation of what is going on, which may actually help the OP learn something. +0

    – Ƭᴇcʜιᴇ007
    Sep 17 '15 at 15:39






  • 1





    Basically adds Null after every comma. Then removes null wherever there is some value after it.

    – jitendragarg
    May 2 '16 at 6:03



















  • Looks good, +1 !

    – duDE
    Sep 17 '15 at 14:21






  • 2





    Looks OK, since it offers no explanation of what is going on, which may actually help the OP learn something. +0

    – Ƭᴇcʜιᴇ007
    Sep 17 '15 at 15:39






  • 1





    Basically adds Null after every comma. Then removes null wherever there is some value after it.

    – jitendragarg
    May 2 '16 at 6:03

















Looks good, +1 !

– duDE
Sep 17 '15 at 14:21





Looks good, +1 !

– duDE
Sep 17 '15 at 14:21




2




2





Looks OK, since it offers no explanation of what is going on, which may actually help the OP learn something. +0

– Ƭᴇcʜιᴇ007
Sep 17 '15 at 15:39





Looks OK, since it offers no explanation of what is going on, which may actually help the OP learn something. +0

– Ƭᴇcʜιᴇ007
Sep 17 '15 at 15:39




1




1





Basically adds Null after every comma. Then removes null wherever there is some value after it.

– jitendragarg
May 2 '16 at 6:03





Basically adds Null after every comma. Then removes null wherever there is some value after it.

– jitendragarg
May 2 '16 at 6:03


















draft saved

draft discarded




















































Thanks for contributing an answer to Super User!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f974353%2ftransforming-csv-into-sql-with-notepad%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Probability when a professor distributes a quiz and homework assignment to a class of n students.

Aardman Animations

Are they similar matrix