Linux sed命令常用方法
sed也成stream editor,流编辑器,是Linux上常用的文本处理工具。
通用格式:sed 行范围 模式/RegExp/ 文件
模式:
d 删除
p 打印符合条件的行
a \string 追加显示(后行)
i \string 追加显示(前行)
r 在某行后插入另一个文本
w 保存到另一个文件
s/pattern/string/ 查找并替换(只替换每行第一个)
s/pattern/string/g 全局替换
1、将test.txt第三行替换为hello输出:
#!/bin/bash
sed "3c hello" test.txt
2、将test.txt第三行替换为hello,并存入原文件:
#!/bin/bash
sed -i "3c hello" test.txt
3、删除test.txt的第一行到第三行:
sed '1,3d' test.txt
4、删除test.txt的第四行到最后一行:
sed '4, $d' test.txt
5、删除包含hello的行:
sed '/hello/d' test.txt
6、删除第5行后的两行:
sed '5, +2d' test.txt
7、hello开头的行后追加一行world
sed '/^hello/a world' test.txt
8、把含有abc的行写入b.txt文件:
sed '/abc/w b.txt' test.txt
9、把/etc/fstab中#开头的行换成#*#
sed 's/^#/#*#/' /etc/fstab
Linux sed命令常用方法的更多相关文章
- linux sed命令参数及用法详解
linux sed命令参数及用法详解 http://blog.csdn.net/namecyf/article/details/7336308 1. Sed简介 sed 是一种在线编辑器,它一次处理一 ...
- [转帖]linux sed命令
linux sed命令就是这么简单 https://www.cnblogs.com/wangqiguo/p/6718512.html 用到的最多的就是一个sed -i 's/nn/mm/' 的命令了. ...
- 理解linux sed命令
理解linux sed命令(2010-02-27 18:21:20) 标签:linuxshellsed替换 分类:革命本钱 1. Sed简介sed是一种在线编辑器,它一次处理一行内容.处理时,把当 前 ...
- 【转】linux sed命令
转自:linux sed命令就是这么简单 参考:Linux三大剑客之sed:https://blog.csdn.net/solaraceboy/article/details/79272344 阅读目 ...
- Linux sed命令 以行为单位编辑文本,或替换文本中的文字
sed -e 4a\newLine testfile 首先查看testfile中的内容如下: $ cat testfile #查看testfile 中的内容 HELLO LINUX! Linux is ...
- Linux sed命令使用方法
sed(Stream Editor)是Linux中文本处理使用非常广泛的工具,可以对文件内容进行替换.删除.新增.选取特定行等功能.下面通过sed常用实例介绍sed命令的使用方法. sed基本语法 s ...
- linux sed命令(擅长输出行)(转)
linux命令总结sed命令详解 Sed 简介 sed 是一种新型的,非交互式的编辑器.它能执行与编辑器 vi 和 ex 相同的编辑任务.sed 编辑器没有提供交互式使用方式,使用者只能在命令行输入编 ...
- linux sed命令详解
简介 sed 是一种在线编辑器,它一次处理一行内容.处理时,把当前处理的行存储在临时缓冲区中,称为“模式空间”(pattern space),接着用sed命令处理缓冲区中的内容,处理完成后,把缓冲区的 ...
- linux sed命令
一.初识sed 在部署openstack的过程中,会接触到大量的sed命令,比如 # Bind MySQL service to all network interfaces. sed -i 's/1 ...
随机推荐
- activity学习(1) 生命周期理解
可以忽略onWindowFocusChanged.onSaveInstanceState.onRestoreInstanceState几个事件,这几个事件官网中的生命周期里面没有提到.忽略掉这几个方法 ...
- hduoj 1077 Catching Fish 求单位圆最多覆盖点个数
Catching Fish Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)To ...
- 转载:用Dreamweave cs 5.5+PhoneGap+Jquery Mobile搭建移动开发
转载地址:http://blog.csdn.net/haha_mingg/article/details/7900221 移动设备应用开发有多难,只要学会HTML5+Javascript就可以.用Dr ...
- cloudera安装hadoop集群和相关服务
一.软件准备: 1.下载cloudera-manager-installer.bin(安装...-server),cdh4.cm(这是...-agent),另外还有些需要的关联软件下步添加. 2.先建 ...
- 【POJ】1056 IMMEDIATE DECODABILITY
字典树水题. #include <cstdio> #include <cstring> #include <cstdlib> typedef struct Trie ...
- 【POJ】2001 Shortest Prefixes
字典树. #include <cstdio> #include <cstring> #include <cstdlib> #define MAXN 26 typed ...
- Quality in the Test Automation Review Process and Design Review Template
About this document Prerequisite knowledge/experience: Software Testing, Test Automation Applicable ...
- HTML---网页编程(1)
前 言 HTML需要和CSS还有JS一起用,才能提现强大. 所以,学了HTML.最好去学学CSS还有JS(JavaScript) ☆静态页面和动态页面 网站页面分为静态页面和动态页面两种 • 静态页面 ...
- leetcode实现 “10001”+“1011” 返回二进制相加的结果
https://oj.leetcode.com/problems/add-binary/ 实” 1 public class Solution { public String addBinary(St ...
- HDU 3480 Division(斜率优化+二维DP)
Division Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 999999/400000 K (Java/Others) Tota ...