Howto split a string on a multi-character delimiter in bash?

Since you’re expecting newlines, you can simply replace all instances of mm in your string with a newline. In pure native bash: in=’emmbbmmaaddsb’ sep=’mm’ printf ‘%s\n’ “${in//$sep/$’\n’}” If you wanted to do such a replacement on a longer input stream, you might be better off using awk, as bash’s built-in string manipulation doesn’t scale well … Read more