manual
http://www.gnu.org/software/sed/manual/sed.html

Overview

  • 使用sed的常见形式
    sed SCRIPT INPUTFILE...
  • 把文件中的‘hello’ 替换为 ‘world’
    sed 's/hello/world/' input.txt > output.txt
  • 不说明输入文件或是输入文件为横杆时候,sed将处理标准输入的内容,下面命令等价
    sed 's/hello/world/' input.txt > output.txt
    sed 's/hello/world/' < input.txt > output.txt
    cat input.txt | sed 's/hello/world/' - > output.txt

  • sed 默认输出是标准输出,用选项 -i ,把编辑的结果保存到文件,而不是把结果打印到标准输出。
    下面的命令会修改文件,没有输出。
    sed -i 's/hello/world/' file.txt
  • sed 默认打印所有要处理的输入行(除非通过d删除的行不打印),选项 -n to suppress output,用-p打印特定行,
    下面的命令打印第3行
    sed -n '45p' file.txt
  • 没有选项-e or -f 时候,sed用第一个非选项参数作为脚本例如('s/hello/world/'),接着的非选项参数作为输入文件。
    如果有选项-e or -f 来指定脚本,所有的非选项参数作为输入文件。-e and -f 可以同时出现多次。
    The following examples are equivalent:
    sed 's/hello/world/' input.txt > output.txt
    sed -e 's/hello/world/' input.txt > output.txt
    sed --expression='s/hello/world/' input.txt > output.txt
    echo 's/hello/world/' > myscript.sed
    sed -f myscript.sed input.txt > output.txt
    sed --file=myscript.sed input.txt > output.txt

命令行选项 Command-Line Options

  • The full format for invoking sed is:
    sed OPTIONS... [SCRIPT] [INPUTFILE...]

linux sed 用法的更多相关文章

  1. linux sed命令参数及用法详解

    linux sed命令参数及用法详解 http://blog.csdn.net/namecyf/article/details/7336308 1. Sed简介 sed 是一种在线编辑器,它一次处理一 ...

  2. Linux sed 和 awk的用法

    sed用法: 原文链接:http://www.cnblogs.com/dong008259/archive/2011/12/07/2279897.html sed是一个很好的文件处理工具,本身是一个管 ...

  3. 【转载】linux之sed用法

    linux之sed用法 原文地址:http://www.cnblogs.com/dong008259/archive/2011/12/07/2279897.html   sed是一个很好的文件处理工具 ...

  4. [转帖]linux之sed用法

    linux之sed用法 https://www.cnblogs.com/dong008259/archive/2011/12/07/2279897.html docker images | awk ' ...

  5. linux学习基础6之sed用法详解

    1 sed 又称为流编辑器,它逐行将文本文件中的行读取到模式空间中间去,将符合编辑条件的行进行编辑后输出到显示器上来.默认sed不编辑原文件只处理模式空间中的内容. 2 sed用法 sed [opti ...

  6. [转帖]linux sed命令

    linux sed命令就是这么简单 https://www.cnblogs.com/wangqiguo/p/6718512.html 用到的最多的就是一个sed -i 's/nn/mm/' 的命令了. ...

  7. learn Linux sed command

    learn Linux sed command 一.参考文档: . sed命令详解 http://qifuguang.me/2015/09/21/sed%E5%91%BD%E4%BB%A4%E8%AF ...

  8. 【转】linux sed命令

    转自:linux sed命令就是这么简单 参考:Linux三大剑客之sed:https://blog.csdn.net/solaraceboy/article/details/79272344 阅读目 ...

  9. Linux sed 替换第一次出现的字符串

    /********************************************************************************* * Linux sed 替换第一次 ...

随机推荐

  1. Beta 冲刺(4/7)

    目录 摘要 团队部分 个人部分 摘要 队名:小白吃 组长博客:hjj 作业博客:beta冲刺(4/7) 团队部分 后敬甲(组长) 过去两天完成了哪些任务 整理博客 ppt模板 接下来的计划 做好机动. ...

  2. 【原创】运维基础之Zabbix(1)简介、安装、使用

    zabbix 4 官方:https://www.zabbix.com/ 一 简介 Monitor anythingSolutions for any kind of IT infrastructure ...

  3. 递归遍历所有xml的节点及子节点

    import java.io.File; import java.util.List; import org.dom4j.Attribute; import org.dom4j.Document; i ...

  4. SQL入门(3):定义约束/断言assertion/触发器trigger

    本文介绍数据库的完整性 完整性控制程序: 指定规则,检查规则 (规则就是约束条件) 动态约束 intergrity constraint::=(O,P,A,R) O : 数据集合, 约束的对象 ?: ...

  5. AI数据分析(三)

    见笔记本 通用函数

  6. 论文阅读笔记四十三:DeeperLab: Single-Shot Image Parser(CVPR2019)

    论文原址:https://arxiv.org/abs/1902.05093 github:https://github.com/lingtengqiu/Deeperlab-pytorch 摘要 本文提 ...

  7. Python内置模块之configparse

    一.概述 1.1.处理的文件形式 configparse 主要是用来处理类似于windows的 ini文件,这个文件的特点是有多个节(section),每个节下会存储多个k=v的值 如下配置 [har ...

  8. HttpClient当HTTP连接的时候出现大量CLOSE_WAIT连接(转)

    ESTABLISHED 表示正在进行网络连接的数量 TIME_WAIT 表示表示等待系统主动关闭网络连接的数量 CLOSE_WAIT 表示被动等待程序关闭的网络连接数量 上篇文章给出了解决TIME_W ...

  9. java反射机构应用

    //atom.getClazzName:package.ClassName Class<?> clazz = Class.forName(atom.getClazzName());     ...

  10. Kali linux2.0里Metasploit的postgresql selected, no connection问题解决

    说在前面的话 1.在kali中metasploit默认使用postgresql作为它的数据库: 想要开启metasploit服务首先得打开postgresql数据库, 命令如下:(或者:/etc/in ...