LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
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 02-11-2014, 07:51 AM   #1
abhishekgit
Member
 
Registered: Jan 2012
Location: India
Distribution: Ubuntu, Gentoo, Fedora, Rhel5,openSUSE
Posts: 165

Rep: Reputation: 12
To dump specific columns of a given file in mysql database.


Hello everyone,
I've been in a problem to dump columns of my choice into a mysql database from a given text file that looks like this.
Quote:
1234 1111 1222 1223
1111 3333 ddsd 1232
2234 4444 1121 1212
3882 0099 1111 1232
1111 8278 3344 1223
Considering the above file is delimited by tabs, how do i extract only columns 2,3,and 4 in the database and ignore the rest. Any help would be appreciated. Thank you.
 
Old 02-11-2014, 08:42 AM   #2
Habitual
LQ Addict
 
Registered: Jan 2011
Posts: 8,563
Blog Entries: 13

Rep: Reputation: Disabled
It may help us to know the desc of the table, so
mysql >
Code:
desc dbname.table;
output please.
 
Old 02-11-2014, 08:54 AM   #3
abhishekgit
Member
 
Registered: Jan 2012
Location: India
Distribution: Ubuntu, Gentoo, Fedora, Rhel5,openSUSE
Posts: 165

Original Poster
Rep: Reputation: 12
I've created a table called Station, which has three attributes namely stationID, X_coord, Y_coord. And the input file, there are around 16 attributes delimited by tabs, in which columns 3,4,and 5 match the attributes of the station table. The problem is to dump only those columns to the database and ignore the others. Thanks for your time
 
Old 02-11-2014, 09:58 AM   #4
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 19,098

Rep: Reputation: 4381Reputation: 4381Reputation: 4381Reputation: 4381Reputation: 4381Reputation: 4381Reputation: 4381Reputation: 4381Reputation: 4381Reputation: 4381Reputation: 4381
Quote:
Originally Posted by abhishekgit View Post
I've created a table called Station, which has three attributes namely stationID, X_coord, Y_coord. And the input file, there are around 16 attributes delimited by tabs, in which columns 3,4,and 5 match the attributes of the station table. The problem is to dump only those columns to the database and ignore the others. Thanks for your time
Not really any problem to solve, since doing a basic MySQL select statement would do it. Have you tried looking at the MySQL documentation on the select statement? Done ANY research on this???

Basic MySQL select, easily found if you tried to look:
https://dev.mysql.com/doc/refman/5.7/en/select.html

Since you apparently want to be fed the answer:
Code:
SELECT field1,field2,field3 FROM table INTO OUTFILE '/some/file.name' FIELDS TERMINATED BY '\t' LINES TERMINATED BY '\n';
...which answers your question: " how do i extract only columns 2,3,and 4 in the database "

However, if you want to LOAD data from a text file into a database, then strip off the first column of data, which will leave you a text file with just the three columns you want. You can use awk for that. Then use the MySQL "load data" command (again, a SMALL bit of research would tell you this):
https://dev.mysql.com/doc/refman/5.7...ng-tables.html

Last edited by TB0ne; 02-11-2014 at 10:02 AM.
 
1 members found this post helpful.
  


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
Text file manipulation: selecting specific lines/columns using awk and print CHARL0TTE Linux - Newbie 2 02-27-2010 02:40 AM
USB enclosure MySQL data dump and file access bbrian017 Linux - Server 16 02-06-2010 01:19 PM
adding a specific shared library file to the rpm database ravalox Linux - Software 0 06-13-2004 01:18 AM
How do I get a dump file (.sql) into MySql? TreeDragon60 Linux - Software 4 03-21-2004 05:19 AM
Need script to dump database, ftp file to backup server glock19 Linux - Networking 17 05-12-2003 05:56 PM

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

All times are GMT -5. The time now is 07:15 PM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration