没有合适的资源?快使用搜索试试~ 我知道了~
gnu sed 使用手册 英文版 sed 是一个流式文本编辑器
资源推荐
资源详情
资源评论

























sed, a stream editor
Next: Introduction, Up: (dir)
sed, a stream editor
This file documents version 4.2.1 of GNU sed, a stream editor.
Copyright © 1998, 1999, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
This document is released under the terms of the GNU Free Documentation License
as published by the Free Software Foundation; either version 1.1, or (at your
option) any later version.
You should have received a copy of the GNU Free Documentation License along with
GNU sed; see the file COPYING.DOC. If not, write to the Free Software Foundation,
59 Temple Place - Suite 330, Boston, MA 02110-1301, USA.
There are no Cover Texts and no Invariant Sections; this text, along with its
equivalent in the printed manual, constitutes the Title Page.
l Introduction: Introduction
l Invoking sed: Invocation
l sed Programs: sed programs
l Examples: Some sample scripts
l Limitations: Limitations and (non-)limitations of GNU sed
l Other Resources: Other resources for learning about sed
l Reporting Bugs: Reporting bugs
l Extended regexps: egrep-style regular expressions
l Concept Index: A menu with all the topics in this manual.
l Command and Option Index: A menu with all sed commands and command-line
options.
--- The detailed node listing ---
sed Programs:
l Execution Cycle: How sed works
l Addresses: Selecting lines with sed
l Regular Expressions: Overview of regular expression syntax
l Common Commands: Often used commands
l The "s" Command: sed's Swiss Army Knife
l Other Commands: Less frequently used commands
l Programming Commands: Commands for sed gurus
l Extended Commands: Commands specific of GNU sed
l Escapes: Specifying special characters
Examples:
l Centering lines
1
1

l Increment a number
l Rename files to lower case
l Print bash environment
l Reverse chars of lines
l tac: Reverse lines of files
l cat -n: Numbering lines
l cat -b: Numbering non-blank lines
l wc -c: Counting chars
l wc -w: Counting words
l wc -l: Counting lines
l head: Printing the first lines
l tail: Printing the last lines
l uniq: Make duplicate lines unique
l uniq -d: Print duplicated lines of input
l uniq -u: Remove all duplicated lines
l cat -s: Squeezing blank lines
Next: Invoking sed, Previous: Top, Up: Top
1 Introduction
sed is a stream editor. A stream editor is used to perform basic text
transformations on an input stream (a file or input from a pipeline). While in
some ways similar to an editor which permits scripted edits (such as ed), sed
works by making only one pass over the input(s), and is consequently more
efficient. But it is sed's ability to filter text in a pipeline which
particularly distinguishes it from other types of editors.
Next: sed Programs, Previous: Introduction, Up: Top
2 Invocation
Normally sed is invoked like this:
sed SCRIPT INPUTFILE...
The full format for invoking sed is:
sed OPTIONS... [SCRIPT] [INPUTFILE...]
If you do not specify
INPUTFILE
, or if
INPUTFILE
is -, sed filters the contents
of the standard input. The
script
is actually the first non-option parameter,
which sed specially considers a script and not an input file if (and only if)
none of the other
options
specifies a script to be executed, that is if neither
of the -e and -f options is specified.
sed may be invoked with the following command-line options:
--version
Print out the version of sed that is being run and a copyright notice, then
2
2

exit.
--help
Print a usage message briefly summarizing these command-
line options and the
bug-reporting address, then exit.
-n
--quiet
--silent
By default, sed prints out the pattern space at the end of each cycle
through the script (see How sed works
). These options disable this automatic
printing, and sed only produces output when explicitly told to via the p
command.
-e
script
--expression=
script
Add the commands in
script
to the set of commands to be run while processing
the input.
-f
script-file
--file=
script-file
Add 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 copy
2
).
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.
-l
N
--line-length=
N
Specify the default line-wrap length for the l
command. A length of 0 (zero)
means to never wrap long lines. If not specified, it is taken to be 70.
--posix
GNU 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
3
3

Bugs) actually violate the standard. If you want to disable only the latter
kind of extension, you can set the POSIXLY_CORRECT variable to a non-empty
value.
-b
--binary
This 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, and sed 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-symlinks
This 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-extended
Use 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
--separate
By 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 R commands are rewound at the start of each file.
-u
--unbuffered
Buffer 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.
Next: Examples, Previous: Invoking sed, Up: Top
3 sed Programs
4
4

A sed program consists of one or more sed commands, passed in by one or more of
the -e, -f, --expression, and --file options, or the first non-option argument if
zero of these options are used. This document will refer to “the” sed script;
this is understood to mean the in-order catenation of all of the
script
s and
script-file
s passed in.
Commands within a
script
or
script-file
can be separated by semicolons (;) or
newlines (ASCII 10). Some commands, due to their syntax, cannot be followed by
semicolons working as command separators and thus should be terminated with
newlines or be placed at the end of a
script
or
script-file
. Commands can also be
preceded with optional non-significant whitespace characters.
Each sed command consists of an optional address or address range, followed by a
one-character command name and any additional command-specific code.
l Execution Cycle: How sed works
l Addresses: Selecting lines with sed
l Regular Expressions: Overview of regular expression syntax
l Common Commands: Often used commands
l The "s" Command: sed's Swiss Army Knife
l Other Commands: Less frequently used commands
l Programming Commands: Commands for sed gurus
l Extended Commands: Commands specific of GNU sed
l Escapes: Specifying special characters
Next: Addresses, Up: sed Programs
3.1 How sed Works
sed maintains two data buffers: the active
pattern
space, and the auxiliary
hold
space. Both are initially empty.
sed operates by performing the following cycle on each line of input: first, sed
reads one line from the input stream, removes any trailing newline, and places it
in the pattern space. Then commands are executed; each command can have an
address associated to it: addresses are a kind of condition code, and a command
is only executed if the condition is verified before the command is to be
executed.
When the end of the script is reached, unless the -n option is in use, the
contents of pattern space are printed out to the output stream, adding back the
trailing newline if it was removed.
3
Then the next cycle starts for the next
input line.
Unless special commands (like ‘D’) are used, the pattern space is deleted
between two cycles. The hold space, on the other hand, keeps its data between
cycles (see commands ‘h’, ‘H’, ‘x’, ‘g’, ‘G’ to move data between both
buffers).
Next: Regular Expressions, Previous: Execution Cycle, Up: sed Programs
5
5
剩余41页未读,继续阅读
资源评论


jinlxz
- 粉丝: 3
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助


最新资源
- 《安装工程预算常用定额项目对照图示》.pdf
- XX业主施工阶段的项目管理.doc
- ASP个人网站发设计方案实现.doc
- 监理工作总结cc.doc
- 观课评教的类型、标准.ppt
- plc和变频器大学本科方案设计书(wo).doc
- XW万能铣床电控系统的PLC设计.doc
- 15-2质量改进程序附表.doc
- 虚拟化技术在医院信息化建设中的实施.docx
- 幼儿园中班语言说课稿:快乐的果园.doc
- 第四章-砌筑工程[1].ppt
- 大学设计单片机-SMS技术智能家居.doc
- 关于通信技术与计算机技术融合发展探究.docx
- 基于区块链技术的电子证据平台应用研究.docx
- 浅议互联网大数据时代技工院校学生思政教育工作的创新.docx
- 中秋活动领导致辞.docx
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈



安全验证
文档复制为VIP权益,开通VIP直接复制
