首页 > 学技术 > 技术网文 > Linux Shell > 正文

[保留] 向高手请教下:pattern space(模式空间) 是什么意思?


来源 chinaunix.net 酷勤网整理

最近看sed1line,出现了2个词,老是在我眼前晃。。。

hold space  

pattern space

上面解释为:

保留空间(内存缓冲区)

模式空间

我发现原文翻译和解释的有写混乱,一开始还说保留空间,最后就不提了,把模式空间说成内存缓冲区了,总之把偶给搞糊涂了。


希望那位高手,能给偶解释下什么是模式空间,嘿嘿,最好通俗点,也最好别说成内存缓冲区啊,那样偶就更糊涂了。。。 :em19:  :em19:  :em19: 

谢谢了!

 :em03:  :em03:  :em03:



 寂寞烈火 回复于:2005-10-02 20:24:11

sed在处理文件的时候,每一行都需要存放在一个叫“模式空间”的临时缓存区!每处理完一行,便清理一次(pattern space),并把下一行再次放入!
而保留空间(hole space),是当sed用到h命令的时候,把匹配的模式放在一个叫做"hold buffer"的保留缓冲里,但需要使用G(sed的取得命令)的时候,sed 从这个保留空间(hold space)中取得(G),....
PS:这是我的理解!我对see了解不多!还是让sed高手释疑吧 :mrgreen:


 yuyuyou 回复于:2005-10-03 00:17:36

谢谢烈火兄!

叫“模式空间”的临时缓存区--------和-------------叫做"hold buffer"的保留缓冲,,,,,,,,,是不是都在内存缓冲区里呢?


不好意思,可能我的理解能力差,所以,还请高人继续点醒我啦。。。

期待!


 寂寞烈火 回复于:2005-10-03 00:33:48

顾名思义,Sed  is a [color=red][u]s[/u][/color]tream [color=red][u]ed[/u][/color]itor,那么,sed处理数据的地方当然是在内存里
PS:跟楼主一齐等待  :em03:


 yuyuyou 回复于:2005-10-04 21:47:51

顶下。


 dradhzn 回复于:2005-10-05 22:09:45

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



 yuyuyou 回复于:2005-10-06 22:57:32

感谢指点!

理解中。。。


 grep_one 回复于:2005-10-07 13:54:12

尝试过确实如此,但看了解释还是不能完全理解,
能说得更详细点吗?


 yuyuyou 回复于:2005-11-23 13:48:42

刚从一个帖子里看到的2位高手的:

dbcat:
引用:
man sed

h H    Copy/append pattern space to hold space.
                                                                                                                              
g G    Copy/append hold space to pattern space.




waker:
引用:
pattern space相当于车间sed把流内容在这里处理
hold space相当于仓库,加工的半成品在这里临时储存 




 dbcat 回复于:2005-11-23 13:53:01

引用:原帖由 yuyuyou 于 2005-11-23 13:48 发表
刚从一个帖子里看到的2位高手的:

dbcat:


waker:
 



http://930699.k43.opensrs.cn/bbs/index.php?showtopic=744 
:em02::em02:蛮可爱的小站啊:em02::em02:


 yuyuyou 回复于:2005-11-23 13:54:43

:oops::oops::oops:


 qbqqq 回复于:2006-03-15 10:18:17

多看看例子就能理解了!


 flowingtree 回复于:2006-06-20 14:54:48

原址: http://www.ascc.sinica.edu.tw/nl/83/1018/03.html



学习









原文链接:http://bbs.chinaunix.net/viewthread.php?tid=621339
转载请注明作者名及原文出处



收藏本页到: