Can someone please explain why this is happening?
This is expected:
$ echo -e "foo\nbar" | sed -n 'h; x; p'
foo
bar
I put every line in the hold space, then swap hold space and pattern space, then print the pattern space, so every line is printed. Now, why is the following different?
$ echo -e "foo\nbar" | sed -n 'h; d; x; p'
I thought that wouldn’t be, because I delete the pattern space before swapping, so the stored line should be put back to the pattern space anyway. It’s the hold space that should be empty after x;, right? I delete the pattern space, then swap. Where does the line I’ve saved go?
I guess it’s related to the following line in
man sed:The following works as expected:
Sorry for bothering you guys.