Sponsored Content
Full Discussion: Duplicate Keys
Top Forums Web Development Duplicate Keys Post 302925805 by blackrageous on Wednesday 19th of November 2014 11:43:09 AM
Old 11-19-2014
I did not have this problem. This implies something is in the table.
I created a testcase of your scenario:

Create these 3 files

file1: testcase (created DB, table and inserts data into file)
Code:
#testcase
set -x
DB="ZYX"
DIR="/var/lib/mysql/${DB}"
FILE="${DIR}/x.csv"

mysql <<EOD
create database ${DB};
use ${DB};
CREATE TABLE Food2 (
PLU CHAR(6) ,
Item varchar(30) ,
Type         varchar(30) ,
Size         varchar(10) ,
InStock      int(5)     ,
OrderPoint   tinyint(5),
OPFlag       tinyint(1),
StockWanted  int(3)   ,
Price        float   ,
WeightFlag   tinyint(1) ,
 PRIMARY KEY (PLU)
);
EOD
cat <<EOD2 > ${FILE} 
3615,"APPLES","Civni",,,,,,,
3630,"APPLES","Co-op 43",,,,,,,
4104,"APPLES","Cortland","Small",10,5,0,15,0.25,1
4106,"APPLES","Cortland","Large",12,5,0,15,0.30,1
4105,"APPLES","Cox Orange Pippin",,,,,,,
4107,"APPLES","Crab",,15,7,0,25,0.15,0
EOD2
mysql << EOD3
use ${DB}
load data infile '${FILE}' into table Food2 fields terminated by ',' enclosed by '"' lines terminated by '\n' ;
EOD3

File 2: testcase.show #shows data in table
Code:
#testcase.show
set -x
DB="ZYX"
DIR="/var/lib/mysql/${DB}"
FILE="${DIR}/x.csv"

mysql <<EOD
use ${DB};
select * from Food2;
EOD

testcase.cleanup #removes DB and table and allows you to retest

Code:
#testcase.cleanupset -x
DB="ZYX"
DIR="/var/lib/mysql/${DB}"
FILE="${DIR}/x.csv"

rm ${FILE}
mysql <<EOD
use ${DB};
drop table Food2;
drop database ${DB};
EOD

To test

Code:
chmod +x testcase*
./testcase
./testcase.show
#try re-importing the data, it will fail
./testcase.cleanup

I was able to insert this csv file with no problems.
I could not recreate your error.
You state that you dropped the table, but you don't show the databases or the tables in your mysql subsystem. This testcase insures there is nothing in the table.
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

arrow keys / special keys

how to use the arrow keys in shell scripting. is there any special synatax / command for this. i just want to use the arrow keys for navigation. replies appreciated raguram R (3 Replies)
Discussion started by: raguramtgr
3 Replies

2. Shell Programming and Scripting

Hot Keys

I am a new user, using Unix in a DOS window. Can I set up Hot Keys to run a script? Example - A12.1.13.15 aaaaBbbbCccc Thank you, cwtlr (8 Replies)
Discussion started by: cwtlr
8 Replies

3. UNIX for Dummies Questions & Answers

SSH keys

Hi everyone, i wanted to generate ssh keys so that i can include the public key in the remote sever, so that for subsequent logins, i can do away with the keying in of the password. I consulted the man ssh-keygen man pages. "..Normally each user wishing to use SSH with RSA or DSA... (1 Reply)
Discussion started by: new2ss
1 Replies

4. UNIX for Advanced & Expert Users

obtain duplicate keys in csv file

Hi, having two csv files, both sorted, by key (column1), f1 containing duplicate keys and f2 containing no duplicate keys, how can I obtain all rows from f1 with the keys listed in file2? Example: f1 is: k1,gsj01fd k2,vi982cj k2,1fjk01e k3,81kjfds k4,sd9dasi f2 is: k2 k3 and I... (3 Replies)
Discussion started by: oscarmon
3 Replies

5. Shell Programming and Scripting

What are public keys in ssh and how do we create the public keys??

Hi All, I am having knowledge on some basics of ssh and wanted to know what are the public keys and how can we create and implement it in connecting server. Please provide the information for the above, it would be helpful for me. Thanks, Ravindra (1 Reply)
Discussion started by: ravi3cha
1 Replies

6. Red Hat

ProxyCommand with different keys

Hello all, simple network problem: host1 -> jumphost -> host2 alias ss='ssh -t -q user2@jumphost -q -t -t ssh -l user2 ' ss host2 works like a charm but scp and scripts don't cooperate very much (normal). My ssh key (user1) is already deployed on jumphost but NOT on host2 as i'm... (0 Replies)
Discussion started by: maverick72
0 Replies

7. Shell Programming and Scripting

Find duplicate based on 'n' fields and mark the duplicate as 'D'

Hi, In a file, I have to mark duplicate records as 'D' and the latest record alone as 'C'. In the below file, I have to identify if duplicate records are there or not based on Man_ID, Man_DT, Ship_ID and I have to mark the record with latest Ship_DT as "C" and other as "D" (I have to create... (7 Replies)
Discussion started by: machomaddy
7 Replies

8. Solaris

help with SSH keys

Hello, I could use some help with my ssh keys and agent. This is the issue. I have 2 different UNIX systems at work. One is the normal Solaris servers with my uid being the same throughout all the servers. I now have a different system for my desktop. A contractor came in and installed some SUN... (0 Replies)
Discussion started by: bitlord
0 Replies

9. Shell Programming and Scripting

Extract values of duplicate keys

I have two questions that are related, so it would be great if you can help me with both! Question1: I have a file A that looks like this: a x b y b z c w I want to get something like: a x b y; z c w Given that a,b,c has no spaces. But the other letters might contain spaces. ... (2 Replies)
Discussion started by: Viernes
2 Replies

10. Shell Programming and Scripting

Find duplicate values in specific column and delete all the duplicate values

Dear folks I have a map file of around 54K lines and some of the values in the second column have the same value and I want to find them and delete all of the same values. I looked over duplicate commands but my case is not to keep one of the duplicate values. I want to remove all of the same... (4 Replies)
Discussion started by: sajmar
4 Replies
csv(n)								  CSV processing							    csv(n)

NAME
csv - Procedures to handle CSV data. SYNOPSIS
package require Tcl 8.3 package require csv ?0.3? ::csv::join values {sepChar ,} ::csv::joinlist values {sepChar ,} ::csv::read2matrix chan m {sepChar ,} {expand none} ::csv::read2queue chan q {sepChar ,} ::csv::report cmd matrix ?chan? ::csv::split line {sepChar ,} ::csv::split2matrix m line {sepChar ,} {expand none} ::csv::split2queue q line {sepChar ,} ::csv::writematrix m chan {sepChar ,} ::csv::writequeue q chan {sepChar ,} DESCRIPTION
The csv package provides commands to manipulate information in CSV FORMAT (CSV = Comma Separated Values). COMMANDS
The following commands are available: ::csv::join values {sepChar ,} Takes a list of values and returns a string in CSV format containing these values. The separator character can be defined by the caller, but this is optional. The default is ",". ::csv::joinlist values {sepChar ,} Takes a list of lists of values and returns a string in CSV format containing these values. The separator character can be defined by the caller, but this is optional. The default is ",". Each element of the outer list is considered a record, these are separated by newlines in the result. The elements of each record are formatted as usual (via ::csv::join). ::csv::read2matrix chan m {sepChar ,} {expand none} A wrapper around ::csv::split2matrix (see below) reading CSV-formatted lines from the specified channel (until EOF) and adding them to the given matrix. For an explanation of the expand argument see ::csv::split2matrix. ::csv::read2queue chan q {sepChar ,} A wrapper around ::csv::split2queue (see below) reading CSV-formatted lines from the specified channel (until EOF) and adding them to the given queue. ::csv::report cmd matrix ?chan? A report command which can be used by the matrix methods format 2string and format 2chan. For the latter this command delegates the work to ::csv::writematrix. cmd is expected to be either printmatrix or printmatrix2channel. The channel argument, chan, has to be present for the latter and must not be present for the first. ::csv::split line {sepChar ,} converts a line in CSV format into a list of the values contained in the line. The character used to separate the values from each other can be defined by the caller, via sepChar, but this is optional. The default is ",". ::csv::split2matrix m line {sepChar ,} {expand none} The same as ::csv::split, but appends the resulting list as a new row to the matrix m, using the method add row. The expansion mode specified via expand determines how the command handles a matrix with less columns than contained in line. The allowed modes are: none This is the default mode. In this mode it is the responsibility of the caller to ensure that the matrix has enough columns to contain the full line. If there are not enough columns the list of values is silently truncated at the end to fit. empty In this mode the command expands an empty matrix to hold all columns of the specified line, but goes no further. The overall effect is that the first of a series of lines determines the number of columns in the matrix and all following lines are truncated to that size, as if mode none was set. auto In this mode the command expands the matrix as needed to hold all columns contained in line. The overall effect is that after adding a series of lines the matrix will have enough columns to hold all columns of the longest line encountered so far. ::csv::split2queue q line {sepChar ,} The same as ::csv::split, but appending the resulting list as a single item to the queue q, using the method put. ::csv::writematrix m chan {sepChar ,} A wrapper around ::csv::join taking all rows in the matrix m and writing them CSV formatted into the channel chan. ::csv::writequeue q chan {sepChar ,} A wrapper around ::csv::join taking all items in the queue q (assumes that they are lists) and writing them CSV formatted into the channel chan. FORMAT
Each record of a csv file (comma-separated values, as exported e.g. by Excel) is a set of ASCII values separated by ",". For other lan- guages it may be ";" however, although this is not important for this case (The functions provided here allow any separator character). If a value contains itself the separator ",", then it (the value) is put between "". If a value contains ", it is replaced by "". EXAMPLE
The record 123,"123,521.2","Mary says ""Hello, I am Mary""" is parsed as follows: a) 123 b) 123,521.2 c) Mary says "Hello, I am Mary" SEE ALSO
matrix, queue KEYWORDS
csv, matrix, queue, package, tcllib csv 0.3 csv(n)
All times are GMT -4. The time now is 08:33 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy