测试数据:

personball@vostro:SHELL$cat aaa
<instrumentation
android:name="aaa"
android:name="aaa"
android:name="aaa"
android:targetPackage="bbbb" />
<application
<uses-library android:name="ccc" />
<uses-library android:name="ccc" />
<uses-library android:name="ccc" />
</application>
<application
<uses-library android:name="ccc" />
</application>
<application
<uses-library android:name="ccc" />
</application>
personball@vostro:SHELL$

根据 匹配,行号 范围执行替换:

personball@vostro:SHELL$sed '/instr/,5 s/"[^"]*"/"999"/' aaa
<instrumentation
android:name="999"
android:name="999"
android:name="999"
android:targetPackage="999" />
<application
<uses-library android:name="ccc" />
<uses-library android:name="ccc" />
<uses-library android:name="ccc" />
</application>
<application
<uses-library android:name="ccc" />
</application>
<application
<uses-library android:name="ccc" />
</application>

根据 匹配,相对匹配行号 范围执行替换:

personball@vostro:SHELL$sed '/<appli/,+1 s/"[^"]*"/"999"/' aaa
<instrumentation
android:name="aaa"
android:name="aaa"
android:name="aaa"
android:targetPackage="bbbb" />
<application
<uses-library android:name="999" />
<uses-library android:name="ccc" />
<uses-library android:name="ccc" />
</application>
<application
<uses-library android:name="999" />
</application>
<application
<uses-library android:name="999" />
</application>
personball@vostro:SHELL$

[2012-06-29]sed根据行号范围执行替换的更多相关文章

  1. sed 使用行号与关键字匹配限定行范围

    1.打印匹配数字4 到最后一行 [111 sed]$ cat input [111 sed]$ sed -n '/4/,$p' input

  2. sed 指定行之间的内容替换

    [root@Cobbler logs]# cat aa.txt qqq123ppp123====123[root@Cobbler logs]# sed -i '2,5s#123#456#' aa.tx ...

  3. sed 指定行范围匹配(转)

    sed -n '5,10{/pattern/p}' file sed是一个非交互性性文本编辑器,它编辑文件或标准输入 导出的文件拷贝.标准输入可能是来自键盘.文件重定向.字符串或变量,或者是一个管道文 ...

  4. sed 指定行范围匹配

    sed -n '5,10{/pattern/p}' file sed是一个非交互性性文本编辑器,它编辑文件或标准输入 导出的文件拷贝.标准输入可能是来自键盘.文件重定向.字符串或变量,或者是一个管道文 ...

  5. vim中使用sed去除网上copy的源代码行号和空格

    有些时候,在网上搜索到的代码都包含有行号,高亮显示控件不支持直接提取,如: test.sh 01 #!/bin/bash 02 echo “aaa” 简单的去掉行号和前面的空格: 方案一: 1.vim ...

  6. Lua中如何实现类似gdb的断点调试—06断点行号检查与自动修正

    前面两篇我们对性能做了一个优化,接下来继续来丰富调试器的特性. 我们前面提到过,函数内并不是所有行都是有效行,空行和注释行就不是有效行.我们之前在添加断点的时候,并没有对行号进行检查,任何行号都能成功 ...

  7. eclipse 对齐行号在括号中显示和字体调整

    笔者 : 本笃庆军 一.括号对齐:指和C/C++里面一样.上下括号对齐~~~ 第一步:Project->preferences->Java->Code Style->Forma ...

  8. python中获取当前位置所在的行号和函数名(转)

    http://www.vimer.cn/2010/12/%E5%9C%A8python%E4%B8%AD%E8%8E%B7%E5%8F%96%E5%BD%93%E5%89%8D%E4%BD%8D%E7 ...

  9. python中获取当前位置所在的行号和函数名(转)

    http://www.vimer.cn/2010/12/%E5%9C%A8python%E4%B8%AD%E8%8E%B7%E5%8F%96%E5%BD%93%E5%89%8D%E4%BD%8D%E7 ...

随机推荐

  1. 单元测试报connection is allready closed导致dailybuild中断的解决方案——类加载机制的应用

    现象; 前段时间在dailybuild过程中,经常遇到connection is allready closed错误,特别是在dailybuild高峰期. 分析定位: 这个错误是的起因比较多,这里的情 ...

  2. css实现鼠标悬浮字体流光背景模糊效果

    原文地址:→看过来 写在前面 有的时候感觉写点小玩意儿挺开心的,还能实践很多的小知识点,所以这次学着写了个有趣的鼠标悬浮模糊效果,只使用了css额. 效果图 源码地址→传送门 预览地址→传送门 小知识 ...

  3. opencv+python3.4的人脸识别----2017-7-19

    opencv3.1  +  python3.4 第一回合(抄代码,可实现):人脸识别涉及一个级联表,目前能力还无法理解. 流程:1.读取图像---2.转换为灰度图---3.创建级联表---4.对灰度图 ...

  4. 【TRICK】解决锚点定位向下浮动Xpx问题

    1. 问题描述 页面滚动后,菜单栏会固定在页头,当锚点定位时,菜单会遮盖部分定位后的内容,所以需要在锚点定位后自动向下漂移Xpx. 2. 解决办法 a. 利用空div 占位,如下: <a hre ...

  5. tensorflow官方文档中的sub 和mul中的函数已经在API中改名了

    在照着tensorflow 官方文档和极客学院中tensorflow中文文档学习tensorflow时,遇到下面的两个问题: 1)AttributeError: module 'tensorflow' ...

  6. spring-boot整合mybatis(1)

    sprig-boot是一个微服务架构,加快了spring工程快速开发,以及简便了配置.接下来开始spring-boot与mybatis的整合. 1.创建一个maven工程命名为spring-boot- ...

  7. WinFrom通过委托传递事件

    今天一个功能需要动态创建pictruebox然后根据时间来倒叙显示,一开始对于这个需求摸不着头脑,后来在公司的大神帮助下实现了,话不多说具体实现上代码了: 1.动态添加控件并倒叙 首先添加一个用户控件 ...

  8. 40. leetcode 202. Happy Number

    Write an algorithm to determine if a number is "happy". A happy number is a number defined ...

  9. POJ3660 Cow Contest floyd传递闭包

    Description N (1 ≤ N ≤ 100) cows, conveniently numbered 1..N, are participating in a programming con ...

  10. Mysql元数据生成Hive建表语句注释脚本

    在将数据从Mysql 等其他关系型数据库 抽取到Hive 表中时,需要同步mysql表中的注释,以下脚本可以生成hive表字段注释修改语句. 注:其他关系型数据库如:oracle 可以通过相同的思路, ...