本文参照sed 4.2.1的man原文翻译。蓝字体为man原文,黑字体是我的译文。
水平有限,难免错漏,欢迎各位指正!
GNU文档的精髓在info页,而不是man页。
当然更希望有同仁将sed的info页翻译出来,方便大家更扎实地运用好sed这个功能强大的工具。
翻译者:李启训。
NAME
名称
sed - stream editor for filtering and transforming text
用于过滤和转换文本的流编辑器。
SYNOPSIS
提要
sed [OPTION]... {script-only-if-no-other-script} [input-file]...
DESCRIPTION
描述
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.
Sed 是一个流编辑器。流编辑器用于转换输入流(文件或者来自管道)的基本文本。虽然在某些方面
它类似于允许脚本编辑的编辑器(比如ed),但是sed只对一次传递的输入进行操作,当然更加高效。除此以外,因为sed能够过滤来自管道中的文本,这明显区别于其他类型的编辑器。 -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
为l命令指定所预期的行的长度。
--posix
disable all GNU extensions.
禁用所有GNU扩展。
-
r, --regexp-extended
use extended regular expressions in the script.
在脚本中使用扩展正则表达式。
-s, --separate
consider files as separate rather than as a single continuous
long stream.
分开多个文件,而不是把多个文件当作一个连续的长“流”。
-u, --unbuffered
load minimal amounts of data from the input files and flush the
output buffers more often
从输出文件导入最少数量的数据,更频繁地刷新输出缓存。
-
-help
display this help and exit
显示这个帮助然后退出。
--version
output version information and exit
输出版本信息然后退出。
If 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.
如果没有指定-e, --expression, -f, 或者 --file选项,第一个无选项参数会被当作sed脚本进行编译。其他所有的参数都认为是输入文件的名称;如果没有指定输入文件,将从标准输入读取输入。
GNU sed home page:</software/sed/>. General help
using GNU software:</gethelp/>. E-mail bug reports
to:<>. Be sure to include the word ``sed'' some‐
where in the ``Sub j ect:'' field.
GNU sed的主页是: </software/sed/>。
使用GNU软件的普通帮助在: </gethelp/>。
报告错误请发到:<>,请务必在“主题”字段中的某个地方包含``sed''字样。
COMMAND SYNOPSIS
命令提要
This is j ust a brief synopsis of sed commands to serve as a reminder to
those who already know sed; other documentation (such as the texinfo
document) must be consulted for fuller descriptions.
这只是sed命令的简单提要,为的是给已经了解sed的人士做一个提醒;其他文档(比如texinfo 文档)一定会有更详细的描述。
Z ero-address ``commands''
不带地址的命令
: label
L abel for b and t commands.
为b或者t命令记上标签。
width的意思中文翻译#comment
The comment extends until the next newline (or the end of a -e
script fragment).
comment可以延伸,直到下一个新行(或者是一个 -e脚本段落的结尾)。
} The closing bracket of a { } block.
{ }块的闭合框。
Z ero- or One- address commands
不带或者只带一个地址的命令。
= Print the current line number.
打印当前行号
a \
text Append text, which has each embedded newline preceded by a back‐
slash.
追加text,text可以通过预先写入反斜杠(\)符号来插入新行。
i \
text Insert text, which has each embedded newline preceded by a back‐
slash.
插入text,text可以通过预先写入反斜杠(\)符号来插入新行。
q [exit-code]
Immediately quit the sed script without processing any more
input, except that if auto-print is not disabled the current
pattern space will be printed. The exit code argument is a GNU
extension.
立刻退出sed脚本而无需处理其他的输入,除非自动打印没有被禁止模式空间被打印出来。
[exit-code]是GUN的扩展。
Q [exit-code]
Immediately quit the sed script without processing any more
input. This is a GNU extension.
立刻退出sed脚本,无需处理任何其他输入。这是GNU的扩展。
r filename
Append text read from filename.
从filename读入text并追加在后面。
R filename
Append a line read from filename. Each invocation of the com‐
mand reads a line from the file. This is a GNU extension.
从filename读入一行并追加在后面。每个命令调用从file中读取一行。这是GNU扩展。
Commands which accept address ranges
接受地址范围的命令
{ Begin a block of commands (end with a }).
开始一个命令块。
b label
Branch to label; if label is omitted, branch to end of script.
程序转移到label处执行;如果label被省略,则转移到脚本结尾。
t label
If a s/// has done a successful substitution since the last
input line was read and since the last t or T command, then
branch to label; if label is omitted, branch to end of script.
如果本次输入行读入之后,离t或者T命令最近的s///结构已经成功替换,那么程序转移到
label处执行;如果label被省略,则转移到脚本结尾。
T label
If no s/// has done a successful substitution since the last
input line was read and since the last t or T command, then
branch to label; if label is omitted, branch to end of script.
This is a GNU extension.
如果本次输入行读入之后,离t或者T命令最近的s///结构没有成功替换,那么程序转移到
label处执行;如果label被省略,则转移到脚本结尾。
c \
text Replace the selected lines with text, which has each embedded
newline preceded by a backslash.
将已选择行替换为text,text可以通过预先写入反斜杠(\)符号来插入新行。
d Delet
e pattern space. Start next cycle.
删除模式空间。开始下一个循环。
D Delete up to the first embedded newline in the pattern space.
Start next cycle, but skip reading from the input if there is
still data in the pattern space.
删除模式空间中的内容,到第一个装入的新行符为止。开始下一个循环,但如果模式空间
中还有数据则暂时不从输入读取。
h H Copy/append pattern space to hold space.
复制/追加模式空间到保存空间。
g G Copy/append hold space to pattern space.
复制/追加保存空间到模式空间。
x Exchange the contents of the hold and pattern spaces.
交换保存空间和模式空间的内容。
l L ist out the current line in a ``visually unambiguous'' form.
用一种“直观明确”的表格列出当前行。
l width
L ist out the current line in a ``visually unambiguous'' form,
breaking it at width characters. This is a GNU extension.
用一种“直观明确”的表格列出当前行,在width个字符内重新组织。这是GNU扩展。
n N Read/append the next line of input into the pattern space.
从输入中读取/追加下一行到模式空间。
p Print the current pattern space.
打印当前模式空间。
P Print up to the first embedded newline of the current pattern
space.
打印当前模式空间,直到第一个装入的新行符为止。
s/regexp/replacement/
Attempt to match regexp against the pattern space. If success‐
ful, replace that portion matched with replacement. The
replacement may contain the special character & to refer to that
portion of the pattern space which matched, and the special
escapes \1 through \9 to refer to the corresponding matching
sub-expressions in the regexp.
尝试在模式空间中匹配 regexp。如果成功则用replacement 替换匹配部分。 replacement
可以包含特殊字符&,来引用模式空间中匹配的部分,而特殊字符\1到\9,则引用regexp
中对应匹配的子表达式。
w filename
Write the current pattern space to filename.
将当前模式空间写到filename中。
W filename
Write the first line of the current pattern space to filename.
This is a GNU extension.
将当前模式空间的第一行写到filename中。这是GNU扩展。
y/source/dest/
Transliterate the characters in the pattern space which appear
in source to the corresponding character in dest.
将模式空间中在source 出现的字符直译为dest 中对应的字符。
Addresses
地址
Sed commands can be given with no addresses, in which case the command
will be executed for all input lines; with one address, in which case
the command will only be executed for input lines which match that
address; or with two addresses, in which case the command will be exe‐
cuted for all input lines which match the inclusive range of lines
starting from the first address and continuing to the second address.
sed命令可以没有指定地址,这种情况下命令将对所有输入行执行;也可以指定一个地址,在这种情况下命令将对匹配地址的输入行执行;或者指定两个地址,在这种情况下,命令将对从匹配的第一个地址开始持续到第二个地址的区域的所有输入行执行。
Three things to note about address ranges: the syntax is addr1,addr2
(i.e., the addresses are separated by a comma); the line which addr1
matched will always be accepted, even if addr2 selects an earlier line;
and if addr2 is a regexp, it will not be tested against the line that
addr1 matched.
关于地址范围,有三件事情需要注意:语法是 addr1,addr2(比如,地址要用逗号隔开); addr1匹配的行将总被接受,即使addr2挑选了一个更靠前的行;如果addr2是一个正则表达式,它将不会测试被addr1匹配过的行。
After the address (or address-range), and before the command, a ! may
be inserted, which specifies that the command shall only be executed if
the address (or address-range) does not match.
a!可能被插入到地址(或者地址范围)之后,命令之前,这就指定了命令将只在地址(或者地址范围)没有被匹配时执行。
The following address types are supported:
支持下列地址类型:
number Match only the specified line number.
数字只匹配指定行数
first~step
Match every step'th line starting with line first. For example,
``sed -n 1~2p'' will print all the odd-numbered lines in the
input stream, and the address 2~5 will match every fifth line,
starting with the second. first can be z ero; in this case, sed
operates as if it were equal to step. (This is an extension.)
匹配从first行开始每间隔step行的行。例如``sed -n 1~2p'' 将打印出输入流的所有奇
数行,而地址2~5将匹配从第二行开始的每间隔五行的行。first可以为0;在这种情况下,
sed按它等于step来执行。(这是扩展。)
$ Match the last line.
匹配最后一行。
/regexp/
Match lines matching the regular expression regexp.
查匹配regexp正则表达式的行。
\cregexpc
Match lines matching the regular expression regexp. The c may
be any character.
查匹配regexp正则表达式的行。c可以是任何字符。
GNU sed also supports some special 2-address forms:
GNU sed也支持一些特殊的两个地址的形式:
0,addr2
Start out in "matched first address" state, until addr2 is
found. This is similar to 1,addr2, except that if addr2 matches
the very first line of input the 0,addr2 form will be at the end
of its range, whereas the 1,addr2 form will still be at the
beginning of its range. This works only when addr2 is a regular
expression.
以“匹配了第一个地址”的状态开始,直到发现地址2【这句话翻译得……不能保证它表达
了英文的原意】。它类似于1,addr2,除了下面这种情况:如果地址2匹配输入的第一行,
0,addr2形式将在该范围的结尾;而1,addr2形式将还是在该范围的开始。这种形式只有在
地址2是个正则表达式的情况下才有效。
addr1,+N
Will match addr1 and the N lines following addr1.
将匹配地址1和地址1之后的N行。
addr1,~N
Will match addr1 and the lines following addr1 until the next
line whose input line number is a multiple of N.
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论