sed命令
2015-06-13 11:27
417 查看
1. 介绍
sed 是一个流编辑器。输入流可以是文件或者管道,sed每次只处理一行,因此更高效,可以过滤管道也是sed区别于其他编辑器的地方。
ed编辑器可以实现脚本化的过滤。
2. 调用
通常sed的调用方式如下:
sed SCRIPT INPUTFILE
完整的格式如下:
set OPTHIONS ... [ SCRIPT ] [ INPUTFILE ]
如果不指定INPUTFILE 或者 INPUTFILE是 - ,那么sed处理来自标准输入的数据。
SCRIPT 实际上是第一个non-option parameter,sed 会当做脚本处理,而不是input file。
--version
Print out the version of sed that is being run and a copyright notice, then
exit.
out the pattern space at the end of each cycle through the script (see How
produces output when explicitly told to via the
processing the input.
to be run while processing the input.
option specifies that files are to be edited in-place. GNU sed does this by creating a temporary file and sending output to this file rather than to the standard output.1.
This option implies -s.
When the end of the file is reached, the temporary file is renamed to the output file's original name. The extension, if supplied, is used to modify the name of the old file before renaming the temporary file, thereby making a backup copy2).
This rule is followed: if the extension doesn't contain a
does contain one or more
files into another directory (provided the directory already exists).
If no extension is supplied, the original file is overwritten without making a backup.
of 0 (zero) means to never wrap long lines. If not specified, it is taken to be 70.
to simplify writing portable scripts, this option disables all the extensions that this manual documents, including additional commands. Most of the extensions
accept sed programs that are outside the syntax mandated by POSIX, but some of them (such as the behavior of the N command described in see Reporting
Bugs) actually violate the standard. If you want to disable only the latter kind of extension, you can set the
When such a distinction is made—as is the case for MS-DOS, Windows, Cygwin—text files are composed of lines separated by a carriage return and a line feed character, andsed does not see the ending CR. When this option is specified, sed will
open input files in binary mode, thus not requesting this special processing and considering lines to end at a line feed.
the command line is a symbolic link, sed will follow the link and edit the ultimate destination of the link. The default behavior is to break the symbolic link, so that the link destination will not be modified.
extended regular expressions rather than basic regular expressions. Extended regexps are those that egrep accepts; they can be clearer because they usually have less backslashes, but are a GNU extension and hence scripts that
use them are not portable. See Extended regular expressions.
line as a single continuous long stream. This GNU sed extension allows the user to consider them as separate files: range addresses (such as ‘/abc/,/def/’) are not allowed to span several files, line numbers are
relative to the start of each file,
useful if the input is coming from the likes of ‘tail -f’, and you wish to see the transformed output as soon as possible.)
If no -e, -f, --expression, or --file options are given on the command-line, then the first non-option argument on the command line is taken to be the script to
be executed.
If any command-line parameters remain after processing the above, these parameters are interpreted as the names of input files to be processed. A
file name of ‘-’ refers to the standard input stream. The standard input will be processed if no file names are specified.
sed 是一个流编辑器。输入流可以是文件或者管道,sed每次只处理一行,因此更高效,可以过滤管道也是sed区别于其他编辑器的地方。
ed编辑器可以实现脚本化的过滤。
2. 调用
通常sed的调用方式如下:
sed SCRIPT INPUTFILE
完整的格式如下:
set OPTHIONS ... [ SCRIPT ] [ INPUTFILE ]
如果不指定INPUTFILE 或者 INPUTFILE是 - ,那么sed处理来自标准输入的数据。
SCRIPT 实际上是第一个non-option parameter,sed 会当做脚本处理,而不是input file。
--version
Print out the version of sed that is being run and a copyright notice, then
exit.
--helpPrint a usage message briefly summarizing these command-line options and the bug-reporting address, then exit.
-n
--quiet
--silentBy default, sed prints
out the pattern space at the end of each cycle through the script (see How
sedworks). These options disable this automatic printing, andsed only
produces output when explicitly told to via the
pcommand.
-escript
--expression=scriptAdd the commands in script to the set of commands to be run while
processing the input.
-fscript-file
--file=script-fileAdd the commands contained in the file script-file to the set of commands
to be run while processing the input.
-i[SUFFIX
]
--in-place[=SUFFIX
]This
option specifies that files are to be edited in-place. GNU sed does this by creating a temporary file and sending output to this file rather than to the standard output.1.
This option implies -s.
When the end of the file is reached, the temporary file is renamed to the output file's original name. The extension, if supplied, is used to modify the name of the old file before renaming the temporary file, thereby making a backup copy2).
This rule is followed: if the extension doesn't contain a
*, then it is appended to the end of the current filename as a suffix; if the extension
does contain one or more
*characters, then each asterisk is replaced with the current filename. This allows you to add a prefix to the backup file, instead of (or in addition to) a suffix, or even to place backup copies of the original
files into another directory (provided the directory already exists).
If no extension is supplied, the original file is overwritten without making a backup.
-lN
--line-length=NSpecify the default line-wrap length for the
lcommand. A length
of 0 (zero) means to never wrap long lines. If not specified, it is taken to be 70.
--posixGNU sed includes several extensions to POSIX sed. In order
to simplify writing portable scripts, this option disables all the extensions that this manual documents, including additional commands. Most of the extensions
accept sed programs that are outside the syntax mandated by POSIX, but some of them (such as the behavior of the N command described in see Reporting
Bugs) actually violate the standard. If you want to disable only the latter kind of extension, you can set the
POSIXLY_CORRECTvariable to a non-empty value.
-b
--binaryThis option is available on every platform, but is only effective where the operating system makes a distinction between text files and binary files.
When such a distinction is made—as is the case for MS-DOS, Windows, Cygwin—text files are composed of lines separated by a carriage return and a line feed character, andsed does not see the ending CR. When this option is specified, sed will
open input files in binary mode, thus not requesting this special processing and considering lines to end at a line feed.
--follow-symlinksThis option is available only on platforms that support symbolic links and has an effect only if option -i is specified. In this case, if the file that is specified on
the command line is a symbolic link, sed will follow the link and edit the ultimate destination of the link. The default behavior is to break the symbolic link, so that the link destination will not be modified.
-r
--regexp-extendedUse
extended regular expressions rather than basic regular expressions. Extended regexps are those that egrep accepts; they can be clearer because they usually have less backslashes, but are a GNU extension and hence scripts that
use them are not portable. See Extended regular expressions.
-s
--separateBy default, sed will consider the files specified on the command
line as a single continuous long stream. This GNU sed extension allows the user to consider them as separate files: range addresses (such as ‘/abc/,/def/’) are not allowed to span several files, line numbers are
relative to the start of each file,
$refers to the last line of each file, and files invoked from the
Rcommands are rewound at the start of each file.
-u
--unbufferedBuffer both input and output as minimally as practical. (This is particularly
useful if the input is coming from the likes of ‘tail -f’, and you wish to see the transformed output as soon as possible.)
If no -e, -f, --expression, or --file options are given on the command-line, then the first non-option argument on the command line is taken to be the script to
be executed.
If any command-line parameters remain after processing the above, these parameters are interpreted as the names of input files to be processed. A
file name of ‘-’ refers to the standard input stream. The standard input will be processed if no file names are specified.
相关文章推荐
- OGRE场景查询
- 【think in java 笔记1】java变量初始化顺序
- php7的安装教程
- [安卓]手机管家(六)防盗之UI及自定义样式
- android 自定义控件 并定义其属性
- Eclipse编译器及一些jdk + notepad
- GitHub入门:如何上传与下载工程?
- 有关宏定义的经验与技巧-简化代码-增强Log
- Tomcat7与IIS7共用80端口
- 系统问题解决的后的思考,处理问题的思路(oracle关不掉,起不来)
- 微信JS-SDK加载验证流程
- 向低权限(低完整性?)进程注入的问题
- 富文本带点击事件的解决方案
- http协议和web本质
- android刮刮卡效果
- Linux LCD驱动(四)--驱动的实现
- 二层交换原理
- 观察者模式--Java设计模式
- office软件
- cpu和gpu各自的作用