Load data from text file in particular format

Discussion in 'MySQL' started by siddharth007, Nov 8, 2012.

  1. #1
    Hi all. I need to insert data from a text file(on my local machine) into a mysql database table.I know that it can be done using 'LOAD DATA INFILE' command in mysql.However i am finding it difficult to parse the rows in my text file for the columns.My text file looks like this

    16:01:46 up 5:25, 2 users, load average: 0.04, 0.22, 0.27
    16:02:55 up 5:27, 2 users, load average: 0.13, 0.22, 0.27

    I need to put them in 5 different fields in my table.

    Note that the row starts with a single blank space.After the first field(i.e. HH:MM:SS) there is a blank space character. After the second field there are two blank spaces. After the third field(H:MM) there is a comma(,) followed by two blank spaces.Same after that.

    Can anyone please help me to parse this pattern.
     
    siddharth007, Nov 8, 2012 IP
  2. kind_of_the_cash

    kind_of_the_cash Active Member

    Messages:
    852
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    85
    #2
    kind_of_the_cash, Nov 8, 2012 IP