I have the following code:
get_list_a()
{
$MYSQL -B -u $USER --passwword="$PW" $DB <<EOF
select name, value from mytable_a
EOF
}
get_list_b()
{
$MYSQL -B -u $USER --passwword="$PW" $DB <<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?
You want all the records from list_A supplemented by all the records from list_B for
which there is not already a matching name in list A. Mathematically this is:
There are many ways of accomplishing this, depending on access and needed efficiencies.
Here is a sample solution to your problem (starting with two lists of names/values):
Here is the output:
This solution, of course, assumes you are allowed to change the order of the records, as is done in the sort step.