data4.txt

this is a test of the test script
this is the second test of the trial script

data6.txt

this is line number 1.
this is line number 2
this is line number 3
this is line number 4

1.sed s 替换命令

 --sed '' data4.txt --每行的第二个

this is a test of the train script
 this is the second test of the trial script

 --sed 's/test/train/g' data4.txt--替换所有

this is a train of the train script

 this is the second train of the trial script

--sed -n 's/test/train/p' data4.txt--替换每行的第一个

this is a train of the test script
this is the second train of the trial script

--sed 's/test/train/w sed_test.txt' data4.txt --替换每行的第一个,输出到sed_test.txt文件

this is a train of the test script
this is the second train of the trial script

2. sed c 替换某一行

sed '3c\this is line changed' data6.txt

this is line number 1.
this is line number 2
this is line changed
this is line number 4

3. sed y 映射替换

--sed 'y/123/789/' data6.txt

this is line number 7.
this is line number 8
this is line number 9
this is line number 4

4. sed d 删除命令

--sed '3d' data6.txt--删除第3行

this is line number 1.
this is line number 2
this is line number 4

--sed '2,3d' data6.txt --删除2,3行

this is line number 1.
this is line number 4

--sed '/1/,/3/d' data6.txt --删除1至3行

this is line number 4

5. sed i 指定行的前面插入一行

  --sed '3i\this is line number 5' data6.txt

this is line number 1.
this is line number 2
this is line number 5
this is line number 3
this is line number 4

--sed '3i\this is line number 6 \n this is line number 5' data6.txt

this is line number 1.
this is line number 2
this is line number 6
this is line number 5
this is line number 3
this is line number 4

6. sed a 在指定行的后面插入一行

  --sed '3a\this is line number 6' data6.txt

this is line number 1.
this is line number 2
this is line number 3
this is line number 6
this is line number 4

7.sed r 将文件插入到指定位置

--sed '3r data12.txt' data6.txt

this is line number 1.
this is line number 2
this is line number 3
this is an add line
this is line number 4

--sed '$r data12.txt' data6.txt --将文件插入末尾

this is line number 1.
this is line number 2
this is line number 3
this is line number 4
this is an add line

8. sed w 写入文件

sed '1,2w test_sed.txt' data6.txt--将1,2行写入test_sed.txt文件

this is line number 1.
this is line number 2

sed编辑的更多相关文章

  1. gerp 查找, sed 编辑, awk 根据内容分析并处理.的作用

    awk(关键字:分析&处理) 一行一行的分析处理 awk '条件类型1{动作1}条件类型2{动作2}' filename, awk 也可以读取来自前一个指令的 standard input相对 ...

  2. mac上执行sed的编辑 -i命令报错sed: 1: "test.txt": undefined label ‘est.txt’或sed: 1: "2a\test\": extra characters after \ at the end of a command

    问题一 sed编辑命令:[sed -i 's/a/b/g' test.txt]   报错:sed: 1: "test.txt": undefined label 'est.txt' ...

  3. sed 命令编辑文本

    1.sed 概述 sed 是一个非交互式文本编辑器.它能够对文本文件和标准输入进行编辑,标准输入能够是来自键盘输入.文件重定向.字符串.变量.甚至来自于管道文本. 2.sed工作流程简述 sed在处理 ...

  4. sed 技巧

    八.流编辑器sed sed ':a;N;$!ba;s/0.01/0.0001/g' file:a 创建一个labelaN 将下一行读入到模式空间$! 如果不是最后一行,ba跳转到label a处s/0 ...

  5. sed

    命令行格式为:         sed [-nefri]  ‘command’  输入文本/文件 常用选项:        -n∶取消默认的输出,使用安静(silent)模式.在一般 sed 的用法中 ...

  6. Shell文本处理 - 匹配与编辑

    正则表达式 符号 含义 . 匹配任意ASCII中任意单个字符,或是字母,或是数字 ^ 匹配行首 $ 匹配行尾 * 匹配任意字符或前一个的一次或多次重复 \ 转义,被转义的有$ . ‘ “ * [ ] ...

  7. linux中sed的用法【转】

    sed命令行格式为:         sed [-nefri]  ‘command’  输入文本/文件 常用选项:        -n∶取消默认的输出,使用安静(silent)模式.在一般 sed 的 ...

  8. grep, sed, awk

    这几个工具是shell中非常好用的文本流处理工具,可以进行查找,编辑或者分析等工作,它们都支持正则表达式,也支持使用shell内置的变量 grep grep是一个字符串比较工具,用于从文件中提取满足条 ...

  9. Shell之sed用法 转滴

    通过例子学习sed的用法 1,sed介绍    sed可删除(delete).改变(change).添加(append).插入(insert).合.交换文件中的资料行,或读入其它档的资料到 文> ...

随机推荐

  1. Android EditText方框验证码 短信验证码的实现

    package com.loaderman.securitycodedemo; import android.graphics.Color; import android.support.v7.app ...

  2. 代码实现:有n个人围成一圈,顺序排号。从第一个人开始报数(从1到3报数),凡报到3的人退出圈子,问最后留下的是原来第几号的那位。

    import java.util.ArrayList; import java.util.List; import java.util.Scanner; //有n个人围成一圈,顺序排号.从第一个人开始 ...

  3. 前端必须掌握的 nginx 技能(3)

    概述 作为一个前端,我觉得必须要学会使用 nginx 干下面几件事: 代理静态资源 设置反向代理(添加https) 设置缓存 设置 log 部署 smtp 服务 设置 redis 缓存(选) 下面我按 ...

  4. Prism 订阅事件 IEventAggregator 说明

    本节学习了Event Aggregation事件聚合,这个在Prism中很重要,特别是对于Module间的通信.除了前面介绍的Command可以用于模块间的通信,还有我们这一节介绍的Event Agg ...

  5. OpenStack RPM Sample 解析

    目录 文章目录 目录 前言 RPM 打包环境安装 RPM 打包流程 OpenStack RPM SPEC Sample RPM 升级/回退 前言 软件功能升级,尤其是 Python 这类解析型语言的软 ...

  6. SAS中的聚类分析方法总结

    SAS中的聚类分析方法总结 说起聚类分析,相信很多人并不陌生.这篇原创博客我想简单说一下我所理解的聚类分析,欢迎各位高手不吝赐教和拍砖. 按照正常的思路,我大概会说如下几个问题: 1.     什么是 ...

  7. 做筛选遍历时遇到的json字符串、json对象、json数组 三者之间的转换问题

    这个是后台对登录用户以及筛选条件的操作 @Override public List<SdSdPer> listResults(String sidx, String sord) { try ...

  8. 关于使用unittest单元测试框架的一些问题集

    1.使用unittest.TestSuites生成的测试套件,使用HtmlTestRunner运行时报Type Error. 1)是由于使用unittest.TestSuites生成的测试套件里的Te ...

  9. 【VS开发】【图像处理】V4L2 pixel format

    目录(?)[-] v4l2_pix_format定义 2 具体Pixel Format定义 1. v4l2_pix_format定义 [cpp] view plain copy /* *  V I D ...

  10. Spring Boot 2.0 多数据源编程

    多数据源配置 创建一个Spring配置类,定义两个DataSource用来读取application.properties中的不同配置.如下例子中,主数据源配置为spring.datasource.p ...