一天一个 Linux 命令(20):sed 命令
本文为joshua317原创文章,转载请注明:转载自joshua317博客 一天一个 Linux 命令(20):sed 命令 - joshua317的博客
一、简介
Linux系统里的sed命令是一种强大的文本处理工具。sed(Stream EDitor)是一种流文件编辑器,它一次处理一行内容。处理时,把当前处理的行存储在临时缓冲区中,称为“模式空间”(Pattern Space),接着用 sed 命令处理缓冲区中的内容,处理完成后,把缓冲区的内容送往屏幕,接着处理下一行,直到文件末尾。
文件内容并没有改变,除非使用-i选项。sed 可依照脚本的指令来处理、编辑文本文件。sed 主要用来编辑一个或多个文件,简化对文件的反复操作或者用来编写转换程序等。
sed 功能同 awk 类似,差别在于sed 简单,对列处理的功能要差一些,awk功能复杂,对列处理的功能比较强大。
二、格式说明
sed [OPTION]... {script-only-if-no-other-script} [input-file]...Usage: sed [OPTION]... {script-only-if-no-other-script} [input-file]...-n, --quiet, --silentsuppress automatic printing of pattern space-e script, --expression=scriptadd the script to the commands to be executed-f script-file, --file=script-fileadd the contents of script-file to the commands to be executed--follow-symlinksfollow symlinks when processing in place-i[SUFFIX], --in-place[=SUFFIX]edit files in place (makes backup if SUFFIX supplied)-c, --copyuse copy instead of rename when shuffling files in -i mode-b, --binarydoes nothing; for compatibility with WIN32/CYGWIN/MSDOS/EMX (open files in binary mode (CR+LFs are not treated specially))-l N, --line-length=Nspecify the desired line-wrap length for the `l' command--posixdisable all GNU extensions.-r, --regexp-extendeduse extended regular expressions in the script.-s, --separateconsider files as separate rather than as a single continuouslong stream.-u, --unbufferedload minimal amounts of data from the input files and flushthe output buffers more often-z, --null-dataseparate lines by NUL characters--helpdisplay this help and exit--versionoutput version information and exitIf no -e, --expression, -f, or --file option is given, then the first
non-option argument is taken as the sed script to interpret. All
remaining arguments are names of input files; if no input files are
specified, then the standard input is read.
其中 OPTION 为命令选项,script-only-if-no-other-script 为处理动作,可以由-e指定多个 定,input-file为输入文件,可指定多个。
三、选项说明
参数说明:
-e
