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. Ubuntu13.04编译安装cmake2.8.12.2

    前提: 安装过程需要gcc和gcc-c++.ubuntu13.04桌面版自带gcc4.7,apt-get install g++4.7安装g++./usr/bin目录下有x86_64-linux-gn ...

  2. 如何修改eclipse中的maven的仓库地址

    最近的有一个朋友问我如何修改eclipse的maven的本地仓库,我想了一下,这个玩意一般是不用修改的,主要是你本地安装的maven在哪个位置,一般的本地仓库位置在 C:\Users\username ...

  3. ffmpeg 视频过度滤镜 gltransition

    ffmpeg 视频过度滤镜 gltransition 上次随笔中提到的 ffmpeg-concat 可以处理视频过度,但是缺点是临时文件超大. 经过查找 ffmpeg 还有 gltransition ...

  4. python关键字参数和位置参数

    关键字参数必须跟随在位置参数后面! 因为python函数在解析参数时, 是按照顺序来的, 位置参数是必须先满足, 才能考虑其他可变参数.,否则报错如下: In [74]: print(s1.forma ...

  5. 【图形学手记】law of the unconscious statistician

    以扔色子为例,结果集为{1,2,3,4,5,6},每个数字出现的概率为1/6 以色子结果为随机变量X,如果我们定义函数F(X) = (X-3)2,我们来计算F(X)的概率分布: X=1,F(1)=(1 ...

  6. 学习SASS

    这几天白老师叫我们css的扩展技术,有什么LESS,还有SASS(我还以为是SAS...QAQ),LESS由于功能比较简单,用的也比较少所以我们重点学习了SASS.简单地说SASS是一种CSS的开发工 ...

  7. gitlab ssh 免密登录

    打开本地git   使用 ssh-keygen 工具 输入命令  ssh-keygen -t rsa -C '你的邮箱账号' 接下来输入密码 确认密码 找到目录 找到公钥 在 gitlab 用户设置  ...

  8. [Python3] 026 常用模块 calendar

    目录 calendar 1. calendar.calendar(year, w, l, c, m) 2. calendar.prcal(year, w, l, c, m) 3. calendar.m ...

  9. Linux单元测试题一

    一. 试验操作题目: 开启Linux操作系统,要求以root用户登录,然后完成下面的操作: 1.查看目前哪些用户登陆到系统上 [root@baidu home]# w 12:41:44 up 45 m ...

  10. python 传址 与传值(暂时保存,后续做分类)

    # python 传址 与 传值 # 定义一个函数 用于将 list 下标为2的数据加100 并进行打印 该list def test1(list): list[2]+=100 print(list) ...