• Linux sed命令笔记 221012


    多个命令分隔 , -e空格 , 分号; , 换行 , {}大括号(花括号)
    3.8 Multiple commands syntax
    ============================
    
    There are several methods to specify multiple commands in a 'sed'
    program.
    
       Using newlines is most natural when running a sed script from a file
    (using the '-f' option).
    
       On the command line, all 'sed' commands may be separated by newlines.
    Alternatively, you may specify each command as an argument to an '-e'
    option:
    
         $ seq 6 | sed '1d
         3d
         5d'
         2
         4
         6
    
         $ seq 6 | sed -e 1d -e 3d -e 5d
         2
         4
         6
    
       A semicolon (';') may be used to separate most simple commands:
    
         $ seq 6 | sed '1d;3d;5d'
         2
         4
         6
    
       The '{','}','b','t','T',':' commands can be separated with a
    semicolon (this is a non-portable GNU 'sed' extension).
    
         $ seq 4 | sed '{1d;3d}'
         2
         4
    
         $ seq 6 | sed '{1d;3d};5d'
         2
         4
         6
    
       Labels used in 'b','t','T',':' commands are read until a semicolon.
    Leading and trailing whitespace is ignored.  In the examples below the
    label is 'x'.  The first example works with GNU 'sed'.  The second is a
    portable equivalent.  For more information about branching and labels
    *note Branching and flow control::.
    
         $ seq 3 | sed '/1/b x ; s/^/=/ ; :x ; 3d'
         1
         =2
    
         $ seq 3 | sed -e '/1/bx' -e 's/^/=/' -e ':x' -e '3d'
         1
         =2
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    CentOS6 sed --help
    用法: sed [选项]... {脚本(如果没有其他脚本)} [输入文件]...
    
      -n, --quiet, --silent
                     取消自动打印模式空间
      -e 脚本, --expression=脚本
                     添加“脚本”到程序的运行列表
      -f 脚本文件, --file=脚本文件
                     添加“脚本文件”到程序的运行列表
      --follow-symlinks
                     follow symlinks when processing in place; hard links
                     will still be broken.
      -i[SUFFIX], --in-place[=SUFFIX]
                     edit files in place (makes backup if extension supplied).
                     The default operation mode is to break symbolic and hard links.
                     This can be changed with --follow-symlinks and --copy.
      -c, --copy
                     use copy instead of rename when shuffling files in -i mode.
                     While this will avoid breaking links (symbolic or hard), the
                     resulting editing operation is not atomic.  This is rarely
                     the desired mode; --follow-symlinks is usually enough, and
                     it is both faster and more secure.
      -l N, --line-length=N
                     指定“l”命令的换行期望长度
      --posix
                     关闭所有 GNU 扩展
      -r, --regexp-extended
                     在脚本中使用扩展正则表达式
      -s, --separate
                     将输入文件视为各个独立的文件而不是一个长的连续输入
      -u, --unbuffered
                     从输入文件读取最少的数据,更频繁的刷新输出
          --help     打印帮助并退出
          --version  输出版本信息并退出
    
    如果没有 -e, --expression, -f 或 --file 选项,那么第一个非选项参数被视为
    sed脚本。其他非选项参数被视为输入文件,如果没有输入文件,那么程序将从标准
    输入读取数据。
    GNU sed home page: <http://www.gnu.org/software/sed/>.
    General help using GNU software: <http://www.gnu.org/gethelp/>.
    E-mail bug reports to: <bug-gnu-utils@gnu.org>.
    Be sure to include the word ``sed'' somewhere in the ``Subject:'' field.
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    CentOS7 sed --help
    用法: sed [选项]... {脚本(如果没有其他脚本)} [输入文件]...
    
      -n, --quiet, --silent
                     取消自动打印模式空间
      -e 脚本, --expression=脚本
                     添加“脚本”到程序的运行列表
      -f 脚本文件, --file=脚本文件
                     添加“脚本文件”到程序的运行列表
      --follow-symlinks
                     直接修改文件时跟随软链接
      -i[SUFFIX], --in-place[=SUFFIX]
                     edit files in place (makes backup if SUFFIX supplied)
      -c, --copy
                     use copy instead of rename when shuffling files in -i mode
      -b, --binary
                     does nothing; for compatibility with WIN32/CYGWIN/MSDOS/EMX (
                     open files in binary mode (CR+LFs are not treated specially))
      -l N, --line-length=N
                     指定“l”命令的换行期望长度
      --posix
                     关闭所有 GNU 扩展
      -r, --regexp-extended
                     在脚本中使用扩展正则表达式
      -s, --separate
                     将输入文件视为各个独立的文件而不是一个长的连续输入
      -u, --unbuffered
                     从输入文件读取最少的数据,更频繁的刷新输出
      -z, --null-data
                     separate lines by NUL characters
      --help
                     display this help and exit
      --version
                     output version information and exit
    
    如果没有 -e, --expression, -f 或 --file 选项,那么第一个非选项参数被视为
    sed脚本。其他非选项参数被视为输入文件,如果没有输入文件,那么程序将从标准
    输入读取数据。
    GNU sed home page: <http://www.gnu.org/software/sed/>.
    General help using GNU software: <http://www.gnu.org/gethelp/>.
    E-mail bug reports to: <bug-sed@gnu.org>.
    Be sure to include the word ``sed'' somewhere in the ``Subject:'' field.
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41

    CentOS9 sed --help

    用法: sed [选项]... {脚本(如果没有其他脚本)} [输入文件]...
    
      -n, --quiet, --silent
                     取消自动打印模式空间
          --debug
                     对程序运行进行标注
      -e 脚本, --expression=脚本
                     添加“脚本”到程序的运行列表
      -f 脚本文件, --file=脚本文件
                     添加“脚本文件”到程序的运行列表
      --follow-symlinks
                     直接修改文件时跟随软链接
      -i[扩展名], --in-place[=扩展名]
                     直接修改文件(如果指定扩展名则备份文件)
      -c, --copy
                     use copy instead of rename when shuffling files in -i mode
      -b, --binary
                     does nothing; for compatibility with WIN32/CYGWIN/MSDOS/EMX 
                     (open files in binary mode; CR+LF are not processed specially)
      -l N, --line-length=N
                     指定“l”命令的换行期望长度
      --posix
                     关闭所有 GNU 扩展
      -E, -r, --regexp-extended
                     在脚本中使用扩展正则表达式
                     (为保证可移植性使用 POSIX -E)。
      -s, --separate
                     将输入文件视为各个独立的文件而不是单个
                     长的连续输入流。
          --sandbox
                     在沙盒模式中进行操作(禁用 e/r/w 命令)。
      -u, --unbuffered
                     从输入文件读取最少的数据,更频繁的刷新输出
      -z, --null-data
                     使用 NUL 字符分隔各行
          --help     打印帮助并退出
          --version  输出版本信息并退出
    
    如果没有 -e, --expression, -f 或 --file 选项,那么第一个非选项参数被视为
    sed脚本。其他非选项参数被视为输入文件,如果没有输入文件,那么程序将从标准
    输入读取数据。
    GNU sed 主页:<https://www.gnu.org/software/sed/>。
    使用 GNU 软件的一般性帮助:<https://www.gnu.org/gethelp/>。
    请将错误报告发送至:<bug-sed@gnu.org>
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44

    Fedora36 sed --help

    用法: sed [选项]... {脚本(如果没有其他脚本)} [输入文件]...
    
      -n, --quiet, --silent
                     取消自动打印模式空间
          --debug
                     对程序运行进行标注
      -e 脚本, --expression=脚本
                     添加“脚本”到程序的运行列表
      -f 脚本文件, --file=脚本文件
                     添加“脚本文件”到程序的运行列表
      --follow-symlinks
                     直接修改文件时跟随软链接
      -i[扩展名], --in-place[=扩展名]
                     直接修改文件(如果指定扩展名则备份文件)
      -c, --copy
                     use copy instead of rename when shuffling files in -i mode
      -b, --binary
                     does nothing; for compatibility with WIN32/CYGWIN/MSDOS/EMX 
                     (open files in binary mode; CR+LF are not processed specially)
      -l N, --line-length=N
                     指定“l”命令的换行期望长度
      --posix
                     关闭所有 GNU 扩展
      -E, -r, --regexp-extended
                     在脚本中使用扩展正则表达式
                     (为保证可移植性使用 POSIX -E)。
      -s, --separate
                     将输入文件视为各个独立的文件而不是单个
                     长的连续输入流。
          --sandbox
                     在沙盒模式中进行操作(禁用 e/r/w 命令)。
      -u, --unbuffered
                     从输入文件读取最少的数据,更频繁的刷新输出
      -z, --null-data
                     使用 NUL 字符分隔各行
          --help     打印帮助并退出
          --version  输出版本信息并退出
    
    如果没有 -e, --expression, -f 或 --file 选项,那么第一个非选项参数被视为
    sed脚本。其他非选项参数被视为输入文件,如果没有输入文件,那么程序将从标准
    输入读取数据。
    GNU sed 主页:<https://www.gnu.org/software/sed/>。
    使用 GNU 软件的一般性帮助:<https://www.gnu.org/gethelp/>。
    请将错误报告发送至:<bug-sed@gnu.org>
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    Fedora36 man sed
    SED(1)									   用户命令									SED(1)
    
    名称
           sed - 文本筛选和格式转换的流式编辑器
    
    摘要
           sed [选项]... {script-only-if-no-other-script} [输入文件]...
    
    描述
           Sed是一个流式编辑器。流式编辑器是用来在输入流(一个文件或者管道输入)中	       完成基本文本转换的。当在一些允许脚本编辑的编辑器中(比如ed),sed通过将
           输入传输为一个输入来工作,这样更高效。但是是sed的功能来过滤管道的文本并 从其他类型的编辑器中特别识别出这些文本。
    
           -n, --quiet, --silent
    
    	      不自动打印模式空间的内容
    
           -e 脚本, --expression=脚本
    
    	      添加脚本到将要执行的命令
    
           -f 脚本文件, --file=脚本文件
    
    	      添加脚本文件的内容到即将执行的命令
    
           --follow-symlinks
    
    	      处理已存在文件时跟随链接
    
           -i[SUFFIX], --in-place[=SUFFIX]
    
    	      编辑已存在的文件(如果提供了SUFFIX作为后缀则做备份)
    
           -l N, --line-length=N
    
    	      指定'l'命令需要的自动换行长度
    
           --posix
    
    	      禁用所有GNU插件。
    
           -E, -r, --regexp-extended
    
    	      在脚本中使用扩展正则表达式(为了可移植性,请使用符合POSIX的-E)
    
           -s, --separate
    
    	      将多个文件分别看待,而非统一视作同个连续的流。
    
           --sandbox
    
    	      在沙箱模式下操作。
    
           -u, --unbuffered
    
    	      从输入文件中读取最少量的数据并更频繁地刷新输出缓冲区
    
           -z, --null-data
    
    	      用NUL字符分割行
    
           --help
    	      显示这个帮助并退出
    
           --version
    	      输出版本信息并退出
    
           如果没有给出-e,--expression,-f,或者--file选项,			     那么第一个非选项参数会被当作sed脚本解释。所有余下的参数是输入文件的名称;
           如果没有指定输入文件,那么就会读取标准输入。
    
           GNU sed主页:。使用GNU软件的通用帮助 :。Bug报告请发送电子邮件至:。
    
    命令摘要
           这只是为已经知道sed命令和相关文档(例如texinfo文档),需要翻阅命令完整 描述的人准备的sed命令的简短摘要。
    
       零地址“命令”
           : label
    	      b 和 t 命令的标签。
    
           #comment
    	      注释将会延长到下一个新行 (或者一个 -e 脚本片段的结尾。)
    
           }      一个{ }块的闭括号。
    
       零或一地址命令
           =      答应当前行的行号。
    
           a \
    
           text   追加 text, text可以通过预先写入反斜杠来嵌入新行。
    
           i \
    
           text   插入 text, text可以通过预先写入反斜杠来嵌入新行。
    
           q [exit-code]
    	      立即退出sed脚本而不处理其他输入,除非自动打印没有禁用使得当前模式 空间将会被打印。[exit-code]是GNU插件(扩展)。
    
           Q [exit-code]
    	      立即退出sed脚本而不处理其他输入。这是一个GNU插件。
    
           r 文件名
    	      从 文件名 读取内容并追加到最后。
    
           R 文件名
    	      从 文件名 读取一行并追加到最后。每次调用这个命令就从文件中读取一 行。这是一个GNU插件。
    
       接受范围地址的命令
           {      开始一个命令块(以一个}结束)。
    
           b label
    	      程序跳转到label处;如果label被省略,跳转到脚本尾部。
    
           c \
    
           text   用 text 代替选择的行, text 可以通过预先写入反斜杠来嵌入新行。
    
           d      删除模式空间。 开始下一个循环。
    
           D      如果模式空间包含新行,在d命令发布之后开始一个新的普通循环。否则,		      删除模式空间中的text直到新行,并且在不读入新行的情况下,用结果的
    	      模式空间开始一个循环。
    
           h H    复制/追加模式空间到保存空间。
    
           g G    复制/追加保存空间到模式空间。
    
           l      用“直观明确”的格式列出当前行。
    
           l width
    	      用“直观明确”的格式列出当前行,在width字符处结束。这是一个GNU插件。
    
           n N    读取/追加下一行输入到模式空间。
    
           p      输出当前的模式空间。
    
           P      输出直到遇到当前模式空间的第一个嵌入的换行符。
    
           s/regexp/replacement/
    	      尝试与模式空间匹配regexp,如果成功,用replacement代替匹配的部分		      。replacement可能包含特殊字符&来引用模式空间中匹配的部分,而特殊
    	      字符\1到\9则引用regexp中对应匹配的子表达式。
    
           t label
    	      自上次输入行读取之后并且上次执行了t或者T命令之后,如果一个s///被 成功替换,那么跳转到label处;如果label被忽略,跳转到脚本结尾。
    
           T label
    	      自上此输入行读取之后并借上次执行了t或者T命令之后,如果一个s///被 成功替换,那么跳转到label处;如果label被忽略,跳转到脚本结尾。这是 一个GNU插件。
    
           w filename
    	      将当前的模式空间写入到filename中。
    
           W filename
    	      写入当前模式空间的第一行到filename中。这是一个GNU插件。
    
           x      交换模式空间和保存空间的内容。
    
           y/source/dest/
    	      将模式空间中显示为source的字符用dest字符来写出。
    
    地址
           Sed命令可以没有指定地址,这样将会为所有行执行命令。如果给出了一个地址,		这样命令就只会为匹配此地址的行执行;如果给出了两个地址,这样命令将会对
           从匹配的第一个地址到第二个地址的区域的所有输入行执行命令。	 关于地址范围有三点:语法为:addr1	   ,	     addr2(比如,地址要用逗号分开);
           addr1匹配的行一定会被接受,即使addr2选定的是更靠前的行;并且如果addr2是 一个regexp(正则表达式),它将不会重复测试addr匹配的行。
    
           在地址(或地址范围)之后,在命令之前,可以插入一个!,这个符号定义的命令 只有在地址(地址范围)不匹配的时候才能执行。
    
           支持下面的地址类型:
    
           number 只匹配行号为number的行。(除非-s选项在命令行中被指定,number值将 会按照文件数渐增。)
    
           first~step
    	      匹配每一个第step行并从first开始计数。举个栗子,``sed	-n	1~2p''将     打印出输入流所有奇数行,而地址2~5将匹配从第2行开始的,以5为步长的
    	      行。first可以是零;这样,sed按其为step来操作。(这是一个插件。)
    
           $      匹配最近的行。
    
           /regexp/
    	      匹配符合正则表达式regexp的行。
    
           \cregexpc
    	      匹配符合正则表达式regexp的行。 其中c可以是任意字符。
    
           GNUsed同样支持某些特殊2地址格式:
    
           0,addr2
    	      从“匹配了第一个地址”状态始,直到发现addr2。这和1,	   addr2很相似,    除了当addr2匹配了输入的第一行,0,	  addr2形式将在该范围的结尾;而	    1,
    	      addr2形式仍然在该范围的开始。这种形式只有在addr2是正则表达式 的情况下才有效。
    
           addr1,+N
    	      将会匹配 addr1 和在 addr1 之后的 N 行。
    
           addr1,~N
    	      将会匹配 addr1 和 addr1 之后的输入行数是 N 倍的下一行。
    
    正则表达式
           POSIX.2	BREs应该是支持的,但是由于性能的原因,这个特性还不完全。其中  \n序列匹配换行符,\a、\t和其他序列也是类似的。-E选项开关用来选择是否使用扩展正则
           表达式;-E选项已经由GNU sed支持了很多年,现已包含于POSIX中。
    
    BUGS
           请将错误报告发送至bug-sed@gnu.org。另外,请在邮件正文中尽量包含 ``sed --version''的信息。
    
    作者
           由 Jay Fenlason, Tom Lord, Ken  Pizzini,	 和  Paolo  Bonzini写成。  GNU	sed  主页:  .	  使用	GNU  软件的一般性手册:
           .  E-mail bug 报告到: .
    
    版权
           Copyright © 2017 Free Software Foundation, Inc.	License GPLv3+: GNU GPL version 3 or later .
           This is free software: you are free to change and redistribute it.  There is NO WARRANTY, to the extent permitted by law.
    
    参见
           awk(1), ed(1), grep(1), tr(1), perlre(1), sed.info, 任何和sed相关的书籍, sed常见问题(http://sed.sf.net/grabbag/tutorials/sedfaq.txt),
           http://sed.sf.net/grabbag/。
    
           sed 的完整文档是作为Texinfo手册维护的。如果info和sed程序正确的安装, 可以执行
    
    	      info sed
    
           命令来访问完整的手册。
    
    跋
           本页面中文版由中文 man 手册页计划提供。
    
           翻译人员:Means Lee
           翻译日期:2017-05-15
           原始软件:sed
           中文 man 手册页计划:https://github.com/man-pages-zh/manpages-zh
    
    sed 4.4									   2017年2月									SED(1)
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87
    • 88
    • 89
    • 90
    • 91
    • 92
    • 93
    • 94
    • 95
    • 96
    • 97
    • 98
    • 99
    • 100
    • 101
    • 102
    • 103
    • 104
    • 105
    • 106
    • 107
    • 108
    • 109
    • 110
    • 111
    • 112
    • 113
    • 114
    • 115
    • 116
    • 117
    • 118
    • 119
    • 120
    • 121
    • 122
    • 123
    • 124
    • 125
    • 126
    • 127
    • 128
    • 129
    • 130
    • 131
    • 132
    • 133
    • 134
    • 135
    • 136
    • 137
    • 138
    • 139
    • 140
    • 141
    • 142
    • 143
    • 144
    • 145
    • 146
    • 147
    • 148
    • 149
    • 150
    • 151
    • 152
    • 153
    • 154
    • 155
    • 156
    • 157
    • 158
    • 159
    • 160
    • 161
    • 162
    • 163
    • 164
    • 165
    • 166
    • 167
    • 168
    • 169
    • 170
    • 171
    • 172
    • 173
    • 174
    • 175
    • 176
    • 177
    • 178
    • 179
    • 180
    • 181
    • 182
    • 183
    • 184
    • 185
    • 186
    • 187
    • 188
    • 189
    • 190
    • 191
    • 192
    • 193
    • 194
    • 195
    • 196
    • 197
    • 198
    • 199
    • 200
    • 201
    • 202
    • 203
    • 204
    • 205
    • 206
    • 207
    • 208
    • 209
    • 210
    • 211
    • 212
    • 213
    • 214
    • 215
    • 216
    • 217
    • 218
    • 219
    • 220
    • 221
    • 222
    • 223
    • 224
    • 225
    • 226
    • 227
  • 相关阅读:
    域对象(request域对象)共享 数据方法(五种servletApi,ModelandVies,Model,map,ModelMap)
    从入门到精通|Yalmip+Cplex在电力系统中的应用(超棒,看不懂算我输,没有收获也算我输)
    Go入门系列:变量声明
    网络编程:组播发送接收
    [数据库]知识点备忘录
    海尔智家:“超预期”成为“新常态”
    带研发团队后的日常思考1 初级管理者的困惑
    Python中文分词及词频统计
    被PMP考试“折磨”出来的考试心得,值得你一览
    elasticsearch官方学习文档
  • 原文地址:https://blog.csdn.net/kfepiza/article/details/127274973