With sed :
$ echo "aaaabbaaabbaa" | sed -r 's/([b]+)/\n\1/g' aaaa bbaaa bbaa
sed -r allows you to block blocks with () and print them with \1 . The block that it catches is [b]+ , which means "one or more b's" , and prints it, preceded by a new line.
As I can see, you are using sed -i , it is also useful to do:
sed -i.bak -r 's/([b]+)/\n\1/g' input.txt
Also easier ( thanks Glenn Jackman !)
$ echo "aaaabbaaabbaa" | sed 's/b\+/\n&/g' aaaa bbaaa bbaa
It replaces all sequences "b" and replaces them with a new line followed by the same sequence "b" ( & represents everything that was matched on the left side of s/// ).
fedorqui
source share