I want to get all the character sequence which match a particular pattern in a string using bash.
Example 1:
Input:
Some random prefix "characters inside quotes".fixed() some random postfix
Output:
characters inside quotes
Example 2:
Input:
Some random prefix "characters inside quotes first".fixed() some random postfix, some random post prefix "characters inside quotes second".fixed() some random post postfix.
Output:
characters inside quotes first
characters inside quotes second
I'm using this script:
input='Some random prefix "characters inside quotes".fixed() some random postfix'
pattern=".* \"(.*)\".fixed()"
[[ $input =~ $pattern ]]
echo "${BASH_REMATCH[1]}"
This works perfectly for Example 1 but not for Example 2. What should i do to generate the correct output for Example 2?