Let\'s say I have a string which contains multiple occurences of the letter Z.
For example: aaZbbZccZ
.
I want to print parts of that string, each time until the nex
This might work for you (GNU sed):
sed -n 's/Z/&\n/g;:a;/\n/P;s/\n\(.*Z\)/\1/;ta' file
Use sed's grep-like option -n
to explicitly print content. Append a newline after each Z
. If there were no substitutions then there is nothing to be done. Print upto the first newline, remove the first newline if the following characters contain a Z
and repeat.