I have a line from some file like this:attempting to create a 512^3 level (with Dirichlet BC) using a 16^3 grid of 32^3 boxes and 800 tasks...I want to extract the 512^3, 16^3, 32^3 and 800 four numbers from it and assign them respectively to four variables level, grid, boxes and tasks for other use.How can I do this?
How do I extract parts of a string to variables?
bash;regular expression;string
Bash can match regular expressions with the =~ operator in [[ ... ]]:#! /bin/bashline='attempting to create a 512^3 level (with Dirichlet BC) using a 16^3 grid of 32^3 boxes and 800 tasks...'num='([0-9^]+)'nonum='[^0-9^]+'if [[ $line =~ $num$nonum$num$nonum$num$nonum$num ]] ; then    level=${BASH_REMATCH[1]}    grid=${BASH_REMATCH[2]}    boxes=${BASH_REMATCH[3]}    tasks=${BASH_REMATCH[4]}    echo Level $level, grid $grid, boxes $boxes, tasks $tasks.fi