Transforming CSV into SQL with Notepad++
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:
- Replace all empty spaces with the String
NULL
- Add at the beginning of each line the String
VALUES (
- 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
add a comment |
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:
- Replace all empty spaces with the String
NULL
- Add at the beginning of each line the String
VALUES (
- 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
You can do it by using "Replace" of Notepad++ with RegEx (regular expression)
– duDE
Sep 17 '15 at 13:53
add a comment |
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:
- Replace all empty spaces with the String
NULL
- Add at the beginning of each line the String
VALUES (
- 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
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:
- Replace all empty spaces with the String
NULL
- Add at the beginning of each line the String
VALUES (
- 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
notepad++ regex csv
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
add a comment |
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
add a comment |
1 Answer
1
active
oldest
votes
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");
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 addsNull
after every comma. Then removes null wherever there is some value after it.
– jitendragarg
May 2 '16 at 6:03
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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");
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 addsNull
after every comma. Then removes null wherever there is some value after it.
– jitendragarg
May 2 '16 at 6:03
add a comment |
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");
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 addsNull
after every comma. Then removes null wherever there is some value after it.
– jitendragarg
May 2 '16 at 6:03
add a comment |
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");
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");
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 addsNull
after every comma. Then removes null wherever there is some value after it.
– jitendragarg
May 2 '16 at 6:03
add a comment |
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 addsNull
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
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
You can do it by using "Replace" of Notepad++ with RegEx (regular expression)
– duDE
Sep 17 '15 at 13:53