Sed——保持空间学习笔记

保持空间(hold space)

将模式空间的内容复制到保持空间,保持空间的内容也可以复制到模式空间,通过命令移动保持空间和模式空间的数据。保持空间用于临时存储,当改变模式空间中的原始内容时,用于保留当前输入行的副本。单独的命令不能寻址保持空间或者更改它的内容。(小写字母命令改写目的缓存区的内容,而大写字母命令追加缓存区的现有内容)

Hold命令在保持空间的内容之后放置一个换行符,且后面跟随模式空间的内容(即使保持空间是空的,换行符也被追加到保持空间中)。

Get命令模式空间的内容之后放置一个换行符,且后面跟随保持空间的内容。

Exchange命令交换两个缓冲区的内容,对两个缓存区没有副作用。

find the Match statement
Consult the Get statement
using the Read statement to retrieve data

/the .* statement/{
        h	# 以改写方式将匹配行存入hold space
        # Pattern space:find the Match statement
        # Hold space:find the Match statement
        s/.*the \(.*\) statement.*/\1/	# 将模式空间中的匹配字符拆分保留the 与 statement之间的字符
        # Pattern space:Match
        # Hold space:find the Match statement
        y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/	# 将模式空间中的保留字符小->大
        # Pattern space:MATCH
        # Hold space:find the Match statement
        G	# 将hold space中的字符追加到pattern space中
        # Pattern space:MATCH\nfind the Match statement
        # Hold space:find the Match statement
        s/\(.*\)\n\(.*the \).*\( statement.*\)/\2\1\3/	# 重新组织字符串
        # Pattern space:find the MATCH statemt
        # Hold space:find the Match statement
}

result:
find the MATCH statement
Consult the GET statement
using the READ statement to retrieve data

请添加图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值