回复 8# moperyblue
你好,又来打扰了。关于你的代码(sed '0,/=/{//h;d};//H;${g;p};d' my.def),有两点不懂,还望能够赐教。谢谢了。 第一点
0,/=/:我不太理解这个的含义。我在网上搜到了关于对0的解释,其中也含有1的解释,但是根据解释,我觉得1,/=/应该是到host3=的那一行。但是却不是,不知道是不是我理解的不对。我贴出来网上搜到的解释和实验代码 0,/regexp/
A line number of 0 can be used in an address specification like 0,/regexp/ so that sed will try to match regexp in the first input line too. In other words, 0,/regexp/ is similar to 1,/regexp/, except that if addr2 matches the very first line of input the 0,/regexp/ form will consider it to end the range, whereas the 1,/regexp/ form will match the beginning of its range and hence make the range span up to the second occurrence of the regular expression.
Note that this is the only place where the 0 address makes sense; there is no 0-th line and commands which are given the 0 address in any other way will give an error.
2.
`h'
Replace the contents of the hold space with the contents of the
pattern space.
`H'
Append a newline to the contents of the hold space, and then
append the contents of the pattern space to that of the hold space. 作者: zy86416779 时间: 2016-07-13 09:45 回复 20# moperyblue
hi,我是知道h和H的含义的。我就是想知道//这个匹配的是什么呢。我做了个实验,我猜是只截取最后一行。还望能够得到比较权威的答复。
`/REGEXP/'
This will select any line which matches the regular expression
REGEXP. If REGEXP itself includes any `/' characters, each must
be escaped by a backslash (`\').
The empty regular expression `//' repeats the last regular
expression match (the same holds if the empty regular expression is
passed to the `s' command). Note that modifiers to regular
expressions are evaluated when the regular expression is compiled,
thus it is invalid to specify them together with the empty regular
expression.