I have a string "st xxx street st st" and i want to change to "street xxx street street street". I can replace middle st, but how can i replace others. Here is my code so far:
#!/bin/bash
SPACE=" "
input="st xxx street st st"
search_string="st"
replace_string="street"
output=${input//$SPACE$search_string$SPACE/$SPACE$replace_string$SPACE}
while [[ $input =~ (^|.* )st( .*|$) ]]; do input="${BASH_REMATCH[1]}street${BASH_REMATCH[2]}"; done; echo "$input"would work but it's too much work