For example:
s1="my_foo"
s2="not_my_bar"
the desired result would be my_o. How do I do this in bash?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
My solution below uses
foldto break the string into one character per line,sortto sort the lists,commto compare the two strings and finallytrto delete the new line charactersAlternatively, here is a pure Bash solution (which also maintains the order of the characters). It iterates over the first string and checks if each character is present in the second string.
prints:
temp_bar