On the next Bash command line, I can get the index for the substring when the substring is between double quotes.
text='123ABCabc((XYZabc((((((abc123(((123' echo $text | awk '{ print index($0, "((((a" )}'
However, in my application, I will not know what character will be, where "a" is in this example. So I thought I could replace âaâ with a regular expression that took any character other than "(" I thought that / [^ (} / would be what I needed. However, I was unable to get the index of the awk command to work with any form of regular expression instead of "(((((a" in the example.
UPDATE: William Pursell noted that the index operation does not accept regex as the second operand.
I ended up trying to extract a substring located after four or more "(" followed by one or more ")". Dennis Williamson provided a solution using the following code:
echo 'dksjfkdj(((((((I-WANT-THIS-SUBSTRING)askdjflsdjf' | mawk '{match($0,/\(\(\(\([^()]*\)/); s = substr($0,RSTART, RLENGTH); gsub(/[()]/, "", s); print s}'
Thank you all for your help!
source share