I have the following code:
get_list_a()
{
$MYSQL -B -u $USER --passwword="$PW" $DB1 <<EOF
select name, value from mytable_a
EOF
}
get_list_b()
{
$MYSQL -B -u $USER --passwword="$PW" $DB2 <<EOF
select name, value from mytable_b
EOF
}
get_list_a >$test.txt
Now I need to combine a and b first and remove all dups(key is name, the first column) and then write them to test.txt. List a and list b by itself are assumed to be distinct. If x in a and y in b exist such that x.name=y.name, then I only want to keep x.
how do I do it? note: merging in SQL is not an option since they are in different db with different collation.
An example:
get_list_a prints
aaa bbb ccc ddd
get_list_b prints
aaa fff ggg hhh
I want the following to be written to the file:
aaa bbb ccc ddd ggg hhh
Would a SQL query along these lines work? (Untested)
Edit: OK, if they’re in separate DBs, and the fields are space-separated as you indicate in a comment, I would probably use associative arrays in perl or awk, letting the values from x (a) overwrite the values from y (b). Something like this (still untested):