phiLLip maDDux II writes:
> Hello,
> 
> I am working on loading data into a table from a text file. I've read
> the documentation on the LOAD DATA command. But I noticed that it only
> works with some kind of delimited file.  Is there any way to load a
> fixed width file???

Hi!

Unfortunately this is not possible with just LOAD DATA INFILE or
`mysqlimport'. :(

You will have to write some small program that parses your file into
some delimited form. For instance here is a simple one in Perl:

  mwagner@evoq ~-> cat datafile 
  aabb
  ccdd
  eeff
  gghh
  1234

  mwagner@evoq ~-> cat deli_parse.pl 
  #!/usr/bin/perl
  
  while (<>) {
     m/^(.{2})(.{2})$/;
     print "$1,$2\n";
  }

  mwagner@evoq ~-> cat datafile | perl ./deli_parse.pl 
  aa,bb
  cc,dd
  ee,ff
  gg,hh
  12,34


Hopefully you can figure out how to adjust the perl regular expression
"m/^(.{2})(.{2})$/;" to suit your needs. Each "(.{2})" unit in the
expression matches one chunk of data 2 characters long, and stores the
trapped data in the variable $1. Adjust the '2' and add more trapping
units to fit your data file.

After you have this file delimited, then it should be trivial to load
it into MySQL using either the LOAD DATA INFILE syntax or the
`mysqlimport' utility.


Regards,

    Matt

-- 
   __  ___     ___ ____  __ 
  /  |/  /_ __/ __/ __ \/ /   Matt Wagner <[EMAIL PROTECTED]>
 / /|_/ / // /\ \/ /_/ / /__  MySQL AB, http://www.mysql.com/
/_/  /_/\_, /___/\___\_\___/  River Falls, Wisconsin, USA
       <___/       Developer


---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to