|
I'll try, but it's not real easy to explain...
s/^M\\$/^M\\/ changes cntl-m backslash to cntl-m backslash. The $ makes this happen only if the pattern is at end of line. This results in no change, but it set a success flag that can be tested later. That is how we know if we want to join the next line.
H appends the pattern area to the hold area. The pattern area is where lines arrive as they are read.
t test to see if that previous s commnand worked or not. If if did, we jump to the end of the script. Well not the last line. This means that we are finished with the current line. So we will read a new line and restart the script.
x exchange. What I really want to do is to retrieve the hold area. Since we are here, the test failed. So we have a line that did not end with cntl-m backslash.
s/\n//g That hold area that I just retrieved is a collection of lines that I want to join. So I delete the newlines.
p print the line. Since there was a -n on the sed command line, no lines are printed automatically.
s/.*// Remove all characters. This empties the pattern area. Thre is a d command, but it has side effects. I usually go with this as my delete.
h copies pattern area to hold area. Now it's empty too.
|