In my bash script, I have an array of filenames like
files=( "site_hello.xml" "site_test.xml" "site_live.xml" )
I need to extract the characters between the underscore and the .xml extension so that I can loop through them for use in a function.
If this were python, I might use something like
re.match("site_(.*)\.xml")
and then extract the first matched group.
Unfortunately this project needs to be in bash, so — How can I do this kind of thing in a bash script? I’m not very good with grep or sed or awk.
Does this answer your question?
Just run the variables through sed in backticks (“)
I don’t remember the array syntax in bash, but I guess you know that well enough yourself, if you’re programming bash 😉
If it’s unclear, dont hesitate to ask again. 🙂