3

Is there a way to use the following command to output in comma separated instead of tab separated.

echo "select col1, col2, col3 from newtable" | mysql --column-names > data.csv

It outputs the following.

col1    col2    col3   
1       Test    Test 1
2       Test    Test 2
3       Test    Test 3

how do I output a comma seperated file.

user3525290
  • 1,231
  • 2
  • 11
  • 31

1 Answers1

3

Just use tr to replace tabulations by commas:

echo "select col1, col2, col3 from newtable" | mysql --column-names | tr "\t" ";" > data.csv
Matthieu.V
  • 122
  • 8