- 论坛徽章:
- 2
|
本帖最后由 zy86416779 于 2016-07-11 22:13 编辑
回复 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.- [root@study awksed]# sed -n '0,/=/p' my.def
- #-----------------------DEFINITIONS-----------------------------
- host1=xxxxx
- [root@study awksed]# sed -n '1,/=/p' my.def
- #-----------------------DEFINITIONS-----------------------------
- host1=xxxxx
- [root@study awksed]#
复制代码 第二点
关于//h和//H。我在网上没有搜到//这个的含义,不知道这个是什么意思。应该不是和s/^$//里面的//含义一样吧?
|
|