Data comparison


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Data comparison
# 1  
Old 08-20-2013
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 ..
Code:
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 xyzSmilie in the shell code .. piping isnt helping

~thanks

Last edited by Franklin52; 08-20-2013 at 09:32 AM.. Reason: Please use code tags
# 2  
Old 08-20-2013
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.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help about comparison

Hello folks, I have two files, which have usernames, I want to see the contents of file1.txt which is missing in file2.txt and another comparison file2.txt contents which is missing in file1.txt. please suggest. file1.txt user u2 u8 a9 p9 p3 u4 z8 aaa ahe oktlo (7 Replies)
Discussion started by: learnbash
7 Replies

2. Shell Programming and Scripting

While loop for comparison

hi all, i have two files: test1 contains : one two three four five (on separate lines) test2 contains: one ten nine (on separate lines) I want to compare two files, test1 against test2. if any word from test1 does not match test2 display it. can someone help me with a while loop on this. ... (4 Replies)
Discussion started by: sbk785
4 Replies

3. UNIX for Dummies Questions & Answers

comparison

hi guys i need a program that can compare a value read from a com-port and one from the terminal. can somebody help me??? using linux kernel 2.6.14-M5 can only use standard function in sh and bash... (5 Replies)
Discussion started by: metal005
5 Replies

4. Shell Programming and Scripting

row Comparison

(5 Replies)
Discussion started by: number10
5 Replies

5. Shell Programming and Scripting

Three Difference File Huge Data Comparison Problem.

I got three different file: Part of File 1 ARTPHDFGAA . . Part of File 2 ARTGHHYESA . . Part of File 3 ARTPOLYWEA . . (4 Replies)
Discussion started by: patrick87
4 Replies

6. Shell Programming and Scripting

$((...)) and $[...] comparison

Does $((mathematical expression)) and $ mean the same? (7 Replies)
Discussion started by: proactiveaditya
7 Replies

7. Shell Programming and Scripting

Extract data based on match against one column data from a long list data

My input file: data_5 Ali 422 2.00E-45 102/253 140/253 24 data_3 Abu 202 60.00E-45 12/23 140/23 28 data_1 Ahmad 256 7.00E-45 120/235 140/235 22 data_4 Aman 365 8.00E-45 15/65 140/65 20 data_10 Jones 869 9.00E-45 65/253 140/253 18... (12 Replies)
Discussion started by: patrick87
12 Replies

8. UNIX for Dummies Questions & Answers

string comparison

Hi Guys i need to write a script to check the file structure I have added the the file headers in the configuration file and execute the file at the start of the script. Now the function checkFileStructure() { echo "Inside the function" filetocheck=$1 fileheader=$2 if ] then... (1 Reply)
Discussion started by: Swapna173
1 Replies

9. Shell Programming and Scripting

need some help..Comparison

I need some help which would probably be for most of you a simple script. I need to read in the data from a .dat file and then compare avg to see who is the highest avg. Here is my script so far. #!/bin/ksh #reading in the data from lab3.dat filename=$1 while read name o1 o2 o3 o4 o5 o6... (0 Replies)
Discussion started by: bluesilo
0 Replies

10. Filesystems, Disks and Memory

comparison

can anyone point me to a comparison of *nix file systems ? i think i prefer a journalling fs but i would like to see a comparison between several fs's before i make up my mind (2 Replies)
Discussion started by: cnf
2 Replies
Login or Register to Ask a Question