Иногда бывают такие «мелочи», о которых со временем забываешь, а потом долго и долго мучаешься как это сделать 🙂
Одна из них — это способ выгрузки из базы данных Mysql напрямик (в крайне удобный для дальнейшего парсинга) CSV данных.
http://stackoverflow.com/questions/356578/how-to-output-mysql-query-results-in-csv-format
На самом деле задача решается довольно-таки просто, и в одну команду из консоли:
Here’s a fairly gnarly way of doing it. Found it somewhere, can’t take any credit
mysql --user=user--password database -B -e "select * from vehicle_categories;" | sed "s/'/\'/;s/\t/\",\"/g;s/^/\"/;s/$/\"/;s/\n//g" > vehicle_categories.csv
Works pretty well. Once again though a regex proves write only.
Regex Explanation:
-
s/// means substitute what’s between the first // with what’s between the second //
-
the «g» at the end is a modifier that means «all instance, not just first»
-
^ (in this context) means beginning of line
-
$ (in this context) means end of line