LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-15-2016, 09:59 AM   #1
jbvijayendra
LQ Newbie
 
Registered: Jun 2016
Posts: 2

Rep: Reputation: Disabled
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
 
Old 06-15-2016, 10:06 AM   #2
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 5,984
Blog Entries: 3

Rep: Reputation: 3115Reputation: 3115Reputation: 3115Reputation: 3115Reputation: 3115Reputation: 3115Reputation: 3115Reputation: 3115Reputation: 3115Reputation: 3115Reputation: 3115
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.
 
1 members found this post helpful.
Old 06-15-2016, 10:08 AM   #3
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,912

Rep: Reputation: 1512Reputation: 1512Reputation: 1512Reputation: 1512Reputation: 1512Reputation: 1512Reputation: 1512Reputation: 1512Reputation: 1512Reputation: 1512Reputation: 1512
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.
 
2 members found this post helpful.
Old 06-15-2016, 10:19 AM   #4
jbvijayendra
LQ Newbie
 
Registered: Jun 2016
Posts: 2

Original Poster
Rep: Reputation: Disabled
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
 
Old 06-15-2016, 10:44 AM   #5
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 24,310

Rep: Reputation: 7148Reputation: 7148Reputation: 7148Reputation: 7148Reputation: 7148Reputation: 7148Reputation: 7148Reputation: 7148Reputation: 7148Reputation: 7148Reputation: 7148
Quote:
Originally Posted by jbvijayendra View Post
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.
 
Old 06-15-2016, 03:38 PM   #6
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,912

Rep: Reputation: 1512Reputation: 1512Reputation: 1512Reputation: 1512Reputation: 1512Reputation: 1512Reputation: 1512Reputation: 1512Reputation: 1512Reputation: 1512Reputation: 1512
Quote:
Originally Posted by jbvijayendra View Post
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.
 
Old 06-15-2016, 04:17 PM   #7
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,325

Rep: Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757
Why FIELDS TERMINATED BY "|" if input file is csv
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Reading comma separated variable into other variables in shell script suryaemlinux Programming 5 12-22-2010 08:38 PM
Reading a .CSV file and then calculating average per minute basis in shell script. krishdeeps Linux - Newbie 1 04-23-2010 05:38 PM
Parsing a comma separated CSV file where fields have commas in to trickyflash Linux - General 7 03-26-2009 04:30 PM
How to delete Comma in a comma separated file with double quotes as quote character pklcnu Linux - Newbie 2 03-24-2009 06:50 PM
Reading comma-separated data from file MeLassen Programming 4 04-04-2004 03:41 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 01:10 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration