- 论坛徽章:
- 0
|
向高手请教下:pattern space(模式空间) 是什么意思?
following explaination could be small but concise , can treat it as a guideline when you study all the sed commands.
Where SED buffers data
SED maintains two data buffers: the active pattern space, and the auxiliary hold space. In "normal" operation, SED reads in one line from the input stream and places it in the pattern space. This pattern space is where text manipulations occur. The hold space is initially empty, but there are commands for moving data between the pattern and hold spaces.
right, a small practice here for SED command "x" :
'x' - Exchange the contents of the hold and pattern spaces.
- say a file contains following 3 lines ,
- #cat file
- line1
- line2
- line3
- #
- by applying 'x' command, the output is as following :
- #sed 'x' file
- line1
- line2
- #
- explain :
- <-- first line is empty , because hold space and pattern space exchange the contents , do remember initially the hold space is empty , now hold space contains line1 after first line data manipulation .
- line1 <- second output is line1, now hold space contains line2 , and so on a so forth . ^_^
- line2
复制代码 |
|