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 next occurence of Z:
aaZ
aaZbbZ
aaZbbZccZ
So I tried using unix sed for this, with the command sed s/Z.*/Z/i
where i is an index that I have running from 1 to the number of Z's in the string. As far as my sed understanding goes: this should delete everything that comes after the i'th Z, But in practice this only works when I have i=1 as in sed s/Z.*/Z/
, but not as I increment i, as in sed s/Z.*/Z/2
for example, where it just prints the entire original string. It feels as if there's something I am missing about the functioning of sed, since according to multiple manuals, it should work.
edit: for example, in the string aaZbbZccZ
while applying sed s/Z.*/Z/2
I am expecting to have aaZbbZ
, as everything after the 2nd occurence of Z get's deleted.