← Back to Archives

Sed SQL

hacks

We recently received some data in an sqldump that we wanted in CSV format.

Here's how you can use sed to tranform it into CSV (from here). This should all be one line...

mysql -u user -p dbname -B -e "SELECT * from table;" | sed 's/\t/","/g;s/^/"/;s/$/"/;s/\n//g' > filename.csv