Mysql + Shell script

Posted on 2006-06-02
Last Modified: 2012-05-05
I have a file which contains data in the below form


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..

Question by:vigneshv10
    1 Comment
    LVL 30

    Accepted Solution

    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.


    Featured Post

    Gigs: Get Your Project Delivered by an Expert

    Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

    Join & Write a Comment

    Introduction In this article, I will by showing a nice little trick for MySQL similar to that of my previous EE Article for SQLite (, A SQLite Tidbit: Quick Numbers Table Generation (…
    All XML, All the Time; More Fun MySQL Tidbits – Dynamically Generate XML via Stored Procedure in MySQL Extensible Markup Language (XML) and database systems, a marriage we are seeing more and more of.  So the topics of parsing and manipulating XM…
    how to add IIS SMTP to handle application/Scanner relays into office 365.
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    745 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now