Data comparison

Hi

I have a linux server with mysql installed.There is some data in mysql tables.
Also.I have a .csv file (not from the aforementioned database)
I need to compare the data in the database nad the .csv and print out the difference.

I tried writing a shell script for that but I was unsuccessful.

I need to ask if there's any way I can export the data from mysql tables to .csv file format and use the diff command to see the comparison of the generated file and the file I had initially.

~thanks

---------- Post updated at 05:59 PM ---------- Previous update was at 05:56 PM ----------

I found one ..

mysql -uexampleuser -pletmein exampledb -B -e "select * from \`person\`;" | sed 's/\t/","/g;s/^/"/;s/$/"/;s/\n//g' > filename.csv

but before select statement could begin,I need to write another statement
use xyz;

how do I induce this (use xyz;) in the shell code .. piping isnt helping

~thanks

In sed, 's/\n//' only works if you do an 'N' to read a second line into the buffer.

Once you have the table into something like a csv file, you need to sort and you may need to deal with excess " and such optional encoding. If there are embedded linefeeds in columns, you need to encode them so lines are rows. If the rows are unique, comm is a good tool, else either diff or preprocess sorted through uniq -c and sed to make dups into unique lines with a count suffix before comm.