免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
12下一页
最近访问板块 发新帖
查看: 5431 | 回复: 12
打印 上一主题 下一主题

向高手请教下:pattern space(模式空间) 是什么意思?  关闭 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2005-10-02 17:17 |只看该作者 |倒序浏览
最近看sed1line,出现了2个词,老是在我眼前晃。。。

hold space  

pattern space

上面解释为:

保留空间(内存缓冲区)

模式空间

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


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

谢谢了!

    

论坛徽章:
1
荣誉会员
日期:2011-11-23 16:44:17
2 [报告]
发表于 2005-10-02 20:24 |只看该作者

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

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

论坛徽章:
0
3 [报告]
发表于 2005-10-03 00:17 |只看该作者

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

谢谢烈火兄!

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


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

期待!

论坛徽章:
1
荣誉会员
日期:2011-11-23 16:44:17
4 [报告]
发表于 2005-10-03 00:33 |只看该作者

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

顾名思义,Sed  is a stream editor,那么,sed处理数据的地方当然是在内存里
PS:跟楼主一齐等待  

论坛徽章:
0
5 [报告]
发表于 2005-10-04 21:47 |只看该作者

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

顶下。

论坛徽章:
0
6 [报告]
发表于 2005-10-05 22:09 |只看该作者

向高手请教下: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.

  1. say a file contains following 3 lines ,
  2. #cat file
  3. line1
  4. line2
  5. line3
  6. #
  7. by applying 'x' command, the output is as following :
  8. #sed 'x' file

  9. line1
  10. line2
  11. #
  12. explain :

  13.             <-- 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 .
  14. line1     <- second output is line1, now hold space contains line2 , and so on a so forth . ^_^
  15. line2
复制代码

论坛徽章:
0
7 [报告]
发表于 2005-10-06 22:57 |只看该作者

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

感谢指点!

理解中。。。

论坛徽章:
0
8 [报告]
发表于 2005-10-07 13:54 |只看该作者

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

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

论坛徽章:
0
9 [报告]
发表于 2005-11-23 13:48 |只看该作者
刚从一个帖子里看到的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相当于仓库,加工的半成品在这里临时储存

论坛徽章:
0
10 [报告]
发表于 2005-11-23 13:53 |只看该作者
原帖由 yuyuyou 于 2005-11-23 13:48 发表
刚从一个帖子里看到的2位高手的:

dbcat:


waker:


http://930699.k43.opensrs.cn/bbs/index.php?showtopic=744
蛮可爱的小站啊
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP