LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Reading comma(,) separated value in Shell script from CSV file (https://www.linuxquestions.org/questions/linux-newbie-8/reading-comma-separated-value-in-shell-script-from-csv-file-4175582327/)

jbvijayendra 06-15-2016 08:59 AM

Reading comma(,) separated value in Shell script from CSV file
 
hi team,

From shell script i want to insert column value which is having comma (,) separated in to Mysql table from CSV file.
like Test1
-----
Test,Test1,Test2

Turbocapitalist 06-15-2016 09:06 AM

Welcome. There are quite a few ways to insert a field, some of them use "awk". What have you tried? We can provide feedback or help where you are getting stuck.

jpollard 06-15-2016 09:08 AM

Actually reading the MySQL manual would answer the question.

http://dev.mysql.com/doc/refman/5.7/en/load-data.html

Google can really help you.

jbvijayendra 06-15-2016 09:19 AM

Here is the format.

`$mysql -uuser -ppassword schema -e 'Load data infile "'$File_Path'" into table table_name CHARACTER SET LATIN1 FIELDS TERMINATED BY "|" OPTIONALLY ENCLOSED BY """" LINES TERMINATED BY "\r\n" IGNORE 1 LINES (column1,column2,column3);'`

Column 2 will be having data like "x,y,z" and it should be inserted as same i.e, x,y,z

TB0ne 06-15-2016 09:44 AM

Quote:

Originally Posted by jbvijayendra (Post 5561223)
Here is the format.

`$mysql -uuser -ppassword schema -e 'Load data infile "'$File_Path'" into table table_name CHARACTER SET LATIN1 FIELDS TERMINATED BY "|" OPTIONALLY ENCLOSED BY """" LINES TERMINATED BY "\r\n" IGNORE 1 LINES (column1,column2,column3);'`

Column 2 will be having data like "x,y,z" and it should be inserted as same i.e, x,y,z

Great...so now is the point where you post what YOU have actually written/tried on your own. We will be happy to help you, but we WILL NOT write your scripts for you. See the "Question Guidelines" link in my posting signature.

Otherwise, check out any of the many, MANY thousands of easily-found bash scripting tutorials you can find with a Google search.

jpollard 06-15-2016 02:38 PM

Quote:

Originally Posted by jbvijayendra (Post 5561223)
Here is the format.

`$mysql -uuser -ppassword schema -e 'Load data infile "'$File_Path'" into table table_name CHARACTER SET LATIN1 FIELDS TERMINATED BY "|" OPTIONALLY ENCLOSED BY """" LINES TERMINATED BY "\r\n" IGNORE 1 LINES (column1,column2,column3);'`

Column 2 will be having data like "x,y,z" and it should be inserted as same i.e, x,y,z

Why don't you READ THE MANUAL.

keefaz 06-15-2016 03:17 PM

Why FIELDS TERMINATED BY "|" if input file is csv


All times are GMT -5. The time now is 11:17 PM.