The behavior of ${VARIABLE/PATTERN/REPLACEMENT} depends on which shell you use and for which version of bash. In the ksh section or in fairly recent versions of bash ${finalt/'</span></td>'/} (think ≥ 4.0) this line is tuned as desired. In earlier versions of bash, quoting is pretty dodgy; you need to write ${finalt/<\/span><\/td>/} (which still works in newer versions).
Since you remove the suffix, you can use the ${VARIABLE%PATTERN} or ${VARIABLE%%PATTERN} construct. Here you delete everything after the first </ , that is, the longest suffix corresponding to the pattern </* . Similarly, you can break the leading HTML tags into ${VARIABLE##PATTERN} .
trimmed=${finalt%%</*}; trimmed=${trimmed##*>}
Added benefit: unlike ${…/…/…} , which is specific to bash / ksh / zsh and works a little differently in all three, ${…#…} and ${…%…} fully portable. They do not do so much, but there are enough of them.
Side note: although this did not cause any problems in this particular instance, you should always put double quotes around variable substitutions , for example
echo "${finalt/'</span></td>'/}"
Otherwise, the shell will expand wildcards and spaces as a result. A simple rule is that if you have no good reason to leave double quotes, you put them.
source share