- 論壇徽章:
- 2
|
本帖最后由 zy86416779 于 2016-07-11 22:13 編輯
回復(fù) 8# moperyblue
你好,又來打擾了。關(guān)于你的代碼(sed '0,/=/{//h;d};//H;${g;p};d' my.def),有兩點(diǎn)不懂,還望能夠賜教。謝謝了。
第一點(diǎn)
0,/=/:我不太理解這個(gè)的含義。我在網(wǎng)上搜到了關(guān)于對0的解釋,其中也含有1的解釋,但是根據(jù)解釋,我覺得1,/=/應(yīng)該是到host3=的那一行。但是卻不是,不知道是不是我理解的不對。我貼出來網(wǎng)上搜到的解釋和實(shí)驗(yàn)代碼
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]#
復(fù)制代碼 第二點(diǎn)
關(guān)于//h和//H。我在網(wǎng)上沒有搜到//這個(gè)的含義,不知道這個(gè)是什么意思。應(yīng)該不是和s/^$//里面的//含義一樣吧?
|
|