Simple comparison between two lists.

I have two lists (input) Alpha and Beta. [Values are tab separated. Now i am showing it separated with = sign]

Alpha:

Beta:

Need the output like this:

I would like to get an output like this:
Alpha vs Beta

| --  | a=1 |
|z=3  | z=4 |

Is it possible ? :cool:

Hello,

Following may help you in same.

$ cat differ_2_files121111.ksh
a=`awk 'NR==FNR {a[$1];next} !($1 in a) {print $1}' check_file_comp2 check_file_comp1`
b=`awk 'NR==FNR {a[$1];next} !($1 in a) {print $1}' check_file_comp1 check_file_comp2`
echo "Alpha vs. Beta "
echo $a "| " $b

Output will be as follows.

Alpha vs. Beta
z=3 |  a=1 z=4

NOTE: Where check_file_comp1(alpha) and check_file_comp2(Beta) are input files.

Thanks,
R. Singh

1 Like

Try also

awk     'NR == FNR      {T[$1]=$2;next}
         $2 == T[$1]    {delete T[$1]; next}
                        {printf "| %s=%s |",$1,$2;
                         if (T[$1]!="") printf " %s=%s |\n", $1, T[$1]
                         else           printf "  -- |\n"
                         delete T[$1]
                        }
         END            {for (i in T) printf "|  -- | %s=%s |\n", i, T}
        ' file1 file2
| a=1 |  -- |
| z=4 | z=3 |
3 Likes

It seems I am getting a different output in this..
can u see this screenshot http://awesomescreenshot.com/0fc2em427d
(Edited the screenshot link)

---------- Post updated at 08:37 PM ---------- Previous update was at 08:33 PM ----------

Ravinder Sing,
This works fine. But my data is little long. (not short as the given example). So I am finding problem using this as it will list all the data in one line !

Real Example

xxxxxxxxxxxxxxxx=11111111111111111111111111111
yyy=66666666666666666666666666666666666666666
zzzzzzzzzzzzzz=uuuuuuuuuuuuuu8888d8fd8fdfd

I can't see your screenshot. What be the difference in the outputs?

Some tweaks to RudiC's solution:

awk '
  NR==1{ printf "%s vrs. ",FILENAME }
  NR==FNR{T[$1]=$2;next}
  FNR==1{ print FILENAME }
  {
    if ($2 != T[$1]) {
        if(T[$1] == "") printf "|  --"
        else printf "| %s=%s", $1, T[$1]
        printf " | %s=%s |\n",$1,$2;
    }
    delete T[$1]
  }
  END {for(i in T) printf "| %s=%s |  -- |\n", i, T}' alpha beta
alpha vrs. beta
|  -- | a=1 |
| z=3 | z=4 |