SED 命令小结

sed maintains two data buffers: the active pattern space, and the auxiliary hold space. Both are initially empty.

When sed reads a file line by line, the line that has been currently read is inserted into the pattern buffer (pattern space). Pattern buffer is like the temporary buffer, the scratchpad where the current information is stored. When you tell sed to print, it prints the pattern buffer.

Hold buffer / hold space is like a long-term storage, such that you can catch something, store it and reuse it later when sed is processing another line. You do not directly process the hold space, instead, you need to copy it or append to the pattern space if you want to do something with it.

sed operates by performing the following cycle on each line of input: first, sed reads one line from the input stream, removes any trailing newline, and places it in the pattern space. Then commands are executed; each command can have an address associated to it: addresses are a kind of condition code, and a command is only executed if the condition is verified before the command is to be executed.

cycle包括从input中读取一行、执行command两步骤,读取一行是必须的,这表示start a cycle就意味着从input中读取了一行。

current line no. 是通过计数器计算的,不管是常规读取还是D等命令读取的,行计数器都是递增的。这也意味着不管怎么读取的,当前行号都是最后一次读取的行的行号。