日期:2014-05-16  浏览次数:20710 次

Linux文本处理–sed命令编辑器

sed编辑器–Stream editor(流编辑器),相对于交互式编辑器如vim无法进行人工交互,需要根据在编辑器处理数据之前事先提供的规则集编辑数据流。

sed编辑器可以根据输入命令行的命令或者存储在文本文件中的命令处理数据。每次从输入读取一行数据,将数据与编辑器提供的命令进行匹配,修改数据流中的数据,然后将心数据输入到stdout。处理完数据流中所有的数据行之后,流编辑器停止。
正是由于按顺序逐行应用命令,因而使得sed编辑器比交互式编辑器要快速。
Usage: sed [OPTION]… {script-only-if-no-other-script} [input-file]…
  -n, –quiet, –silent
                 suppress automatic printing of pattern space
  -e script, –expression=script
                 add the script to the commands to be executed
  -f script-file, –file=script-file
                 add the contents of script-file to the commands to be executed
  –follow-symlinks
                 follow symlinks when processing in place
  -i[SUFFIX], –in-place[=SUFFIX]
                 edit files in place (makes backup if extension supplied)
  -l N, –line-length=N
                 specify the desired line-wrap length for the `l’ command
  –posix
                 disable all GNU extensions.
  -r, –regexp-extended
                 use extended regular expressions in the script.
  -s, –separate
                 consider files as separate rather than as a single continuous