By amazing coincidence, I was playing around with this
exact command earlier today, as an exercise in understanding the hold buffer.
(Actually, not that much of a coincidence. It was your other thread that prompted me to do so.)
As I mentioned there, see
grymoire tutorial, particularly the section on multi-line commands, for the full rundown on the commands.
There's also a good blog that has breakdowns of of one-liner commands like this in
sed and
awk and such.
http://www.catonmat.net/blog/sed-one...ined-part-one/
(This one is #36 on the above page)
But to try to explain it myself, lets break the expression up into it's individual commands:
Don't print lines by default.
Ignore the first line, but for every subsequent line append the contents of the hold buffer to the current line in the pattern buffer, separated by a newline character.
Copy the modified contents of the pattern buffer to the hold buffer, replacing the previous contents. Remember that the first line was unmodified by the previous command, so it's copied as-is.
On the final line, print the contents of the pattern buffer, after having the hold contents appended to it in the first command. Note that since this is the last line, the 'h' command in the final step runs, but has no further effect.
So what it does is store a copy of line one, then when it reaches line two, attaches that copy to the end of it, stores the result, appends the both of them to line 3, and so on to the end of the file, when it prints the whole thing.
But yeah,
tac is probably a better choice for this particular job. Although the
sed command is more flexible since it could be modified to do other things like extracting and reversing only certain lines.