List:General Discussion« Previous MessageNext Message »
From:Paul DuBois Date:September 5 2001 1:13am
Subject:Re: output to csv
View as plain text  
At 7:59 AM +0800 9/5/01, Steve Doig wrote:
>Hi Folks,
>I'm running a batch command in win2K: cmd> mysql < batch-file > output.txt
>In the batch file, can I specify that values are separated by commas instead
>of tabs?

No, but if you have Perl installed, you can create a file named
that contains the following:

while (<>)              # read next input line
     s/"/""/g;           # double any quotes within column values
     s/\t/","/g;         # put `","' between column values
     s/^/"/;             # add `"' before the first value
     s/$/"/;             # add `"' after the last value
     print;              # print the result
exit (0);

Then you can run this command:

cmd> mysql < batch-file | perl > output.txt

and output.txt will contain CSV output.  If you have a file association
set up so that .pl files get executed by Perl, you can shorten that to:

cmd> mysql < batch-file | > output.txt


Paul DuBois, paul@stripped
output to csvSteve Doig5 Sep
  • Re: output to csvColin Faber5 Sep
  • Re: output to csvPaul DuBois5 Sep
  • Re: output to csvBenjamin David Hildred5 Sep