Link to home
Start Free TrialLog in
Avatar of enthuguy
enthuguyFlag for Australia

asked on

compare two variables and get common values

Hi
I have a comma separated values in two variables, would like to compare both variables and get values which are available in both variables.

leftString="ami-06bc7b1fd6d88be49,ami-04db3b64b5f3990dd,ami-0063dd4d697377715,ami-01f8ea3141121cda4,ami-083a15980f7fcf2ad,ami-0b22b5f710211"
rightstring="ami-023d322923f1bb271,ami-0390dfc7d966ce65d,ami-04db3b64b5f3990dd,ami-05f492333c31e3971,ami-066e692403bb98cd3,ami-06bc7b1fd6d88be49,ami-07ebe2d3da06f1831,ami-0a621c6a67fc67a3f,ami-0afa5ade0d61726ef,ami-0b41712d2aef56be1,ami-0f0b1e112bdf5034f"

Open in new window


what we are expecting in the final variable as below..since they are in both.
compareString="ami-06bc7b1fd6d88be49,ami-04db3b64b5f3990dd"

Open in new window


thanks in advance
Avatar of enthuguy
enthuguy
Flag of Australia image

ASKER

I was playing around using comm but no luck yet

NAME
       comm - compare two sorted files line by line

SYNOPSIS
       comm [OPTION]... FILE1 FILE2

DESCRIPTION
       Compare sorted files FILE1 and FILE2 line by line.
       With no options, produce three-column output.  Column one contains lines unique to FILE1, column two contains lines unique to FILE2, and column three contains lines common to both files.

       -1     suppress column 1 (lines unique to FILE1)
       -2     suppress column 2 (lines unique to FILE2)
       -3     suppress column 3 (lines that appear in both files)

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of skullnobrains
skullnobrains

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks very much, that was very helpful