We help IT Professionals succeed at work.

adding a mysql column to a tab delimited file

andieje asked
Last Modified: 2012-05-11

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

Watch Question

Aaron TomoskyDirector, SD-WAN Solutions

If you open it in excel it's pretty easy to add a autoincrement Pk column
Top Expert 2012

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
Distinguished Expert 2019

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.


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


My ultimate objective is to get the autoinc primary key into the tab file using a script and not a spreadsheet
Distinguished Expert 2019
Unlock this solution and get a sample of our free trial.
(No credit card required)


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
Distinguished Expert 2019

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?


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
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.