Quote:
Originally Posted by ghostdog74
beautiful as a one liner. not beautiful when you want to decipher it
|
That
is a neat line. Looking back I should've tried something like it myself. I almost did, but I decided to try my hand at awk instead (I've just finished reading through the
Unix Grymoire and I'm trying to learn more about both programs).
The nice thing about it is that it uses the little-known sed hold buffer. To break it down, assuming I'm reading it correctly, the first part of the command matches the line '<ItemTitle>', then grabs the next line following it as well (the N command), stores them both in the hold buffer (h), and deletes the pattern space so that it can go on to the next command (d). The second expression then matches the <ItemBarcode> line and appends the contents of the hold buffer to it (G). That's it.
Actually, I think the real reason I went with awk was that I was having a bit of trouble understanding exactly how sed's hold buffer works in practice. This real-world example has helped a lot.