I have looked for hours for an answer, so I have decided to request your guidance.
I want to substract the first number (series of digits) contained in a string. This string is the output of another command. The substring (number) can be located at any position inside the string.
I want to use only the bash string manipulation facilities, as to avoid using other commands (sed, awk, etc.).
The Advanced Bash-Scripting Guide: Manipulating Strings section specifies that index is used to get the "Numerical position in $string of first character in $substring that matches".
However, it does not state whether "substring" can be a regular expression or not. After trying things like
expr index "$string" '[0-9]'
expr index "$string" '[0-9]*'
I reached to the conclusion that substring cannot be a regular expression. Please confirm if this is correct. I know, I learn slow.
Now I found out that this can be solved with a command like
$(echo "$string" | /bin/awk '{print match($0,"[0-9]")}')
but this is what I wanted to avoid in the first place
So I want to confirm with you guys if there is a way in which I could accomplish this without using external commands.
Thanks a lot, and I hope this post will eventually help others.