I am trying to dynamically extract unique patterns from a list of filenames in bash.
Input list of filenames looks like this
Exp1_ML_Rep1.txt,Exp1_ML_Rep2.txt,Exp1_ML_Rep3.txt
I want to dynamically extract the strings
Rep1,Rep2,Rep3
Shown diagrammatically here:
NOTE: The input pattern can change every time e.g. another use case may be
Exp2_DT_10ng_55C_1_User1.png,Exp2_DT_10ng_55C_2_User1.png,Exp2_DT_10ng_55C_3_User1.png
In this case, I want to extract
1,2,3
Shown diagrammatically here:
What is the best way to achieve this in bash?
As recommended in the comments, I tried the following:
declare -p string1 string2
declare -- string1="ER_Rep1"
declare -- string2="ER_Rep2"
diff <(echo "$string1" ) <(echo "$string2")
which returns
1c1
< ER_Rep1
---
> ER_Rep2
What I am trying to extract is Rep1,Rep2.

