[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 821
  • Last Modified:

Mysql + Shell script

I have a file which contains data in the below form

test1:value1:test9
test2:value2:test9
test3:value3:test9

I need only the first two values in each of the lines in the file which has to be inserted in a database.

I would require this script to run everytime the file is modified. could you tell me how to do this..

probably a shell script..

thanks
0
vigneshv10
Asked:
vigneshv10
1 Solution
 
todd_farmerCommented:
You can use the LOAD DATA INFILE syntax within MySQL to load the data:

LOAD DATA INFILE filename INTO TABLE tablename FIELDS TERMINATED BY ':' (column1, column2, @skip_data);

You would need a shell script to invoke this.  You could save the above into a file called load.sql, and invoke a shell script that contains the following:

mysql --user=user_name --password=pass db_name < load.sql

In terms of invoking it whenever the file changes, that's outside the realm of MySQL, but I'm sure you might be able to do this any number of ways in a shell script.

0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now