Link to home
Start Free TrialLog in
Avatar of andieje
andieje

asked on

adding a mysql column to a tab delimited file

Hi

I have a mysql database with a table called Feature and an autoinc primary key.
I also have a tab delimited file with one row per feature. This file does not contain the Feature autoinc primary key. The rows in the tab delimited file are in the same order as the rows were inserted into the mysql database.

Basically i want to add the feature_id pk as a column to this tab delimited file. I could write a script but I was wondering if there was an easier way to export a mysql table column(s) to an existing tab delimted file

I've tried searching for this but all the results that come back just tell me how to export data as a new tab file but i want to add to an existing file

thanks
Avatar of Aaron Tomosky
Aaron Tomosky
Flag of United States of America image

If you open it in excel it's pretty easy to add a autoincrement Pk column
Is your ultimate objective to import the file into the table?  Why not just use the load data command, map the columns, and let the auto_increment in mysql assign the values?

See http://dev.mysql.com/doc/refman/5.1/en/load-data.html
Is the data in the mysql database complete, accurate and have the identical information that is in your tab delimited file??
If the answer is Yes, given that you want to match the id column from the mysql to the name in the Tab delimited file, exporting the data from mysql is the way to go.
Alternatively, you can insert a column in your Tab delimited file while it is open in excel, or openoffice equivalent or use a while/for loop
to add an autoincrementing number to each row.
A2 =($A1+1)
Fill down
Note that Saving data in a tab delimited/comma delimited value format will only save the values and strip out the function.
Avatar of andieje
andieje

ASKER

I should have pointed out that i want the process to be automated by a script or a mysql command i can call from a shell script.

Yes, arnold, the data in the database is identical to the data in the tab file except that the tab file doesn't have the autoinc primary key
Avatar of andieje

ASKER

My ultimate objective is to get the autoinc primary key into the tab file using a script and not a spreadsheet
ASKER CERTIFIED SOLUTION
Avatar of arnold
arnold
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of andieje

ASKER

that just exports the fields from the table into a new file and not into my existing tab file.

However i could then merge the 2 tables with the paste command
If the tab file is the same data that you imported what is the issue with exporting the data back that will include the auto-increament?

What is the end goal for you?
Avatar of andieje

ASKER

the tab file i have now contains a lot more data than the data that was originally imported. i just wanted to add the id from the database to it (i wasn't going to import the new extended data set)

but exporting the id and pasting the 2 files works fine