HOME > é»ç® > ed ã¡ã¢
ed ã¡ã¢
ed ã¯äœ¿ã£ãŠæ¥œãããšãã£ã¿ããïŒæ£ç¢ºã«èšããªãã°ããšãã£ã¿ãé²æ©ãããããã§ãããããã¯æ¥œãããšæãããšãã ã ed ã䜿ãã°ããã®ã§ããïŒãã¿ããªã§äœ¿ãããã以äžã¯ GNU ed 0.2 ã§è©Šãããã®ã
ãã®åã« gnu.org ã«çœ®ããŠãããžã§ãŒã¯ã«ãªã³ã¯ã貌ã£ãŠãããããªã
http://www.gnu.org/fun/jokes/ed.html äžè¡ç®ã«æžããŠããã®ã¯ ed ããšãã¥ã¬ãŒãïŒïŒïŒããã·ã§ã«ã»ã¹ã¯ãªããã
http://www.gnu.org/fun/jokes/ed.msg.html ããã¯ãããã¥ã¢ã«ïŒïŒïŒã
ãšãã«åè«ã ãã念ã®ããã
ç®æ¬¡
ed åã©ãã
äžå¿ã®çŽ¹ä»
ed ã¯å¯Ÿè©±çã«äœ¿ãããã¹ããšãã£ã¿ã§ããïŒãã¡ããããã§ãªã䜿ãæ¹ãã§ãããïŒããã®ç¹ã§ã¯ãEmacs ã vi ãšå€ããããªããed ã«ã¯ã³ãã³ãã¢ãŒããšå ¥åã¢ãŒããããããã®ç¹ã§ã¯ Emacs ãšç°ãªããvi ã«åãã§ãããed ã«ã¯ã«ãŒãœã«ãšãããã®ããªããã«ã¬ã³ããã€ã³ããšããæŠå¿µã¯ãªããçŸåšè¡ãšããæŠå¿µã ããããããã®ç¹ã§ vi ãšç°ãªãããããŠãed ãæã€å€èŠäžã®æ倧ã®ç¹åŸŽã¯ãæ瀺çã«èŠæ±ãããªãéããããã¡ã®å 容ã衚瀺ããªããšããããšã§ãããã€ãŸããed ã¯ã¹ã¯ãªãŒã³ãšãã£ã¿ã§ã¯ãªãã
ed ã®ã³ãã³ãã®å€ãã¯ã1 å以äžã®ã¢ãã¬ã¹ã«ããè¡šçŸããã 1 ã€ä»¥äžã®è¡ã察象ãšããŠå®è¡ããããïŒããšãã° vi ã® x ã³ãã³ãã¯ã«ãŒãœã«äžã®äžæåã察象ãšããŠå®è¡ããããããã®ãããªç䌌㯠ed ã«ã¯ã§ããªãïŒãããã¯å€èŠäžã«ã«ãŒãœã«ããªãããšã«åŒå¿ããŠããããããè¡ã®äžã®äžéšåã«å€æŽãå ããããªãã°ããã®è¡ã察象ãšããŠçœ®æã³ãã³ãã䜿ãããšã«ãªãã
æäœéç¥ã£ãŠããã¹ãããšã¯ãa ã³ãã³ãã«ããçŸåšè¡ã®åŸãã«æ°ããè¡ãæ¿å ¥ããå ¥åã¢ãŒãã«å ¥ããããªãªãã²ãšã€ã ãã®è¡ãå ¥åãããšå ¥åã¢ãŒããçµäºãããšããããšã§ããã
ãããŠãããããã¶ãäžçªå€§äºãªã®ã ããed ãçµäºãããã³ãã³ã㯠q ã§ãããïŒãããã¡ã«å 容ããããä¿åãããŠããªãç¶æ 㧠q ã³ãã³ããæã€ãšãä¿åãä¿ãããã« ? ãè¿ãããå Žåããããããããããå Žåã¯å床 q ã³ãã³ããæã€ãšçµäºã§ããïŒ
ã¢ãã¬ã¹ã®æå®
ed ã¯ããã©ã«ãã§ã¯ã³ãã³ãã¢ãŒãã«ãããŠããã³ããã衚瀺ããªãã以äžã®äŸã§ã¯ã·ã§ã«ããã
$ ed -p'> ' test.txt
ãšã㊠ed ãèµ·åããã³ãã³ãããã³ãããšã㊠> ã衚瀺ããããã«ããŠãããããã¯ããã«ãã®ããŒãžãèªã¿ããããã®ã«ããããã§ããã
ed ã®ã³ãã³ãã¯ã[address[,address]]command[parameters] ãšããæ§é ãæã€ãšããã¥ã¢ã«ã«æžããŠãããããã ãèŠããšãcommand ã®ãšããã«ãååž°çã« [address[,address]]command[parameters] å šäœãå ¥ããããšãã§ãããã«èŠããããããã¯ã§ããªãã
ã³ãã³ãã¯ã³ãã³ãã«å眮ãããã¢ãã¬ã¹ã瀺ãè¡ã«å¯ŸããŠå®è¡ãããããã³ãã³ãã«ãããå¿ èŠãšããã¢ãã¬ã¹ã®åæ°ãç°ãªããããšãã°ãp ã³ãã³ãã¯äºã€ã®ã¢ãã¬ã¹ãå¿ èŠãšããããããæãïŒäºã€ã®ã¢ãã¬ã¹èªäœãå«ãïŒç¯å²ã衚瀺ããã
äžè¬çã«äºã€ã®ã¢ãã¬ã¹ãå¿ èŠãšããã³ãã³ãã«ãããŠãã¢ãã¬ã¹ã 1 ã€ããæå®ãããªãã£ãå Žåãäºã€ç®ã®ã¢ãã¬ã¹ã«äžã€ç®ãšåããã®ãæå®ããããšè§£éãããããããã£ãŠã
> 5,5p > 5,p > 5p
ã¯åãããšãæå³ãããããã 5 è¡ç®ã®å 容ã衚瀺ãããïŒp ã¯ãããã¡ã®å 容ã衚瀺ããã³ãã³ãïŒ
è足ãªããèšã£ãŠãããšãed ã察話çã«äœ¿ããã以äžãã¢ãã¬ã¹ãçç¥ããæ©äŒã¯å€ãããããã£ãŠã¢ãã¬ã¹ã®å šéšãŸãã¯ããã€ããçç¥ããå Žåã®åäœãããç解ããŠããããšã ed ç¿åŸã®äžã€ã®éµãšãªãã
äžè¬ã«ãã¢ãã¬ã¹ã 1 åãæå®ãããªãã£ãå Žåãããã©ã«ãã®åäœã¯ã³ãã³ãã«ããç°ãªããããšãã°ãp ã§ã¯çŸåšè¡ã 1 ã€ç®ãš 2 ã€ç®ã®ã¢ãã¬ã¹ãšããŠæå®ããããšè§£ããããã€ãŸããçŸåš 10 è¡ç®ã«ãããªã
> 10,10p > p
ã® 2 ã€ã¯åãããšãæå³ããã
= ã¯ãæå®ãããè¡ã®è¡çªå·ã衚瀺ããã³ãã³ãã§ãããäžã€ã®å¯Ÿè±¡ã¢ãã¬ã¹ããæåŸ ããŠããªããããã©ã«ãã¯æçµè¡ã§ããããããã£ãŠãçŸåš 10 è¡ç®ã«ãããšãããã€ããã®ãã¡ã€ã«ã 10 è¡ããå€ãè¡ãæã£ãŠãããªãã°ã
> 10= > =
ã¯ãç°ãªãè¡çªå·ã衚瀺ãããçŸåšè¡ã®è¡çªå·ãç¥ããããªãã°ãçŸåšè¡ã®ã¢ãã¬ã¹ã瀺ã .ïŒããªãªãïŒã䜿ã£ãŠã
> .=
ãšããå¿ èŠãããããã®ã»ãã«ãç¹å¥ãªã¢ãã¬ã¹ã瀺ããã®ã« $ ããããæçµè¡ãããããã
ãŸããç¹å¥ãªã¢ãã¬ã¹ç¯å²ããããããã®ãšããŠã% ãš , ãããããšãã«ãããã¡ã®æåã®è¡ããæåŸã®è¡ãŸã§ãããããããããã£ãŠã
> 1,$p > %p > ,p
ã¯ããããããããã¡ã®å šå 容ã衚瀺ãããããã« ; ã¯çŸåšè¡ããæçµè¡ãŸã§ãããããããããã£ãŠã
> .,$p > ;p
ã¯åãããšãæå³ãããïŒãã ããåŸè¿°ã®ãªãã»ããã䜿ã£ã .,$-p ã¯ãçŸåšè¡ããæçµè¡ã®äžè¡åãŸã§ã衚瀺ããã®ã«å¯ŸããŠã;-p ãšããé¡æåã¿ãããªãã®ã¯ Invalid address ãšããŠãšã©ãŒã«ãªã£ãŠããŸãïŒã
ã¢ãã¬ã¹ã¯ãªãã»ãããæå®ããããšãã§ãã- ãŸã㯠^ ã¯åã®è¡ã瀺ãã+ ã¯æ¬¡ã®è¡ã瀺ãã-- ã +++ ã®ããã«éããŠäœ¿ãããšãã§ãã-- 㯠-2ã++ 㯠+2 ãšæžããŠãåãã§ããããããã£ãŠã
> 10p > 9+p > 8+2p > 12--p > 6+2+2p > 10+2-2p
ã¯ãããã 10 è¡ç®ã衚瀺ããããªãã»ããã¯ãåºæºãšãªãã¢ãã¬ã¹ãæå®ãããŠããªãå Žåã«ã¯ãçŸåšè¡ãåºæºã«åãããããã£ãŠãçŸåš 10 è¡ç®ã«ãããªãã
> +p > +1p > ++-p > +2-p
ã¯ãã¹ãŠ 11 è¡ç®ã衚瀺ããã
= ã«ãããŠãããã¯ããŠã¯ãŸãã-= 㯠.-= ãæå³ãããã®ã§ãã£ãŠã$-= ãæå³ãããã®ã§ã¯ãªããïŒcf. ã¢ãã¬ã¹ããŸã£ããæå®ãããŠããªãå Žåã= 㯠$= ãšåãã§ããïŒã
ã¢ãã¬ã¹ã¯ã³ãã³ããæåŸ ããããå€ãã®åæ°ãæå®ããããšãã§ãããã®å Žåãã³ãã³ãã¯å¿ èŠãªã¢ãã¬ã¹ã®æ°ã ããæå®ãããã¢ãã¬ã¹ãåŸããã䜿ãã
p ã¯äºã€ã®ã¢ãã¬ã¹ãæåŸ ããŠããããã
> 10,11p > 9,10,11p > 12,10,11p
ã¯åãããšãæå³ããããŸãã= ã¯äžã€ã®ã¢ãã¬ã¹ãæåŸ ããŠããããã
> 3= > 10,3= > 10,1,3=
ã¯åãããšãæå³ããã
ã³ãã³ãã«ãã£ãŠäœ¿ãããªãã¢ãã¬ã¹ã¯ãäœãæžããŠãããããšããã°ãããã§ã¯ãªããåŸç¶ããã¢ãã¬ã¹ã¯ãå
è¡ããã¢ãã¬ã¹ãšåãè¡ãããã以åŸã®è¡ã瀺ããã®ã§ãªããŠã¯ãªããªããšããäžè¬çãªèŠåã«ã¯ãããã§ãåŸããªããŠã¯ãªããªãããšä¿¡ããŠãããã ããå
çšè©ŠããããŠãœã§ããã
ãã®ä»æ§ã¯ãä»ã®ãšããæå³ããªãããã«èŠãããããã€ã¯åœ¹ã«ç«ã€ãšããããšãåŸã§è¿°ã¹ãã
æ£èŠè¡šçŸã«ããã¢ãã¬ã¹æå®
ed ã§ã¯ãæ£èŠè¡šçŸã䜿ã£ãã¢ãã¬ã¹æå®ãå¯èœã§ããã/dog/ ãšããã¢ãã¬ã¹ãæå®ãããšãçŸåšè¡ã®æ¬¡ã®è¡ããæçµè¡ã«åãã£ãŠãdog ãšãããã¿ãŒã³ãæ€çŽ¢ããããããäžè¡ç®ã«æ»ã£ãŠçŸåšè¡ãŸã§ãæ€çŽ¢ããããã¿ãŒã³ãçºèŠããããšãåæ¢ãããã®è¡çªå·ãã¢ãã¬ã¹ãšããŠæå®ããã®ãšåãå¹æã瀺ããçŸåšè¡ãæåŸã«æ¢çŽ¢ãããç¹ã«æ³šæã
. * ^ $ [ ] \( \) \1 \2 ... ã®ãããã¯ãã»ãŒ sed ãšåãããã«äœ¿ãããïŒãšãããããed æµã®è¡šçŸã sed ã«éºäŒããŠããã®ã§ãããïŒ
/æ£èŠè¡šçŸ/ ã®ãããã« ?æ£èŠè¡šçŸ? ã䜿ããšãçŸåšè¡ã®åã®è¡ãããããã¡ã®å é ã«åãã£ãŠæ€çŽ¢ãããå é ã«éãããšãããã¡ã®æçµè¡ã«ãã©ããçŸåšè¡ãŸã§ãæ€çŽ¢ããã/æ£èŠè¡šçŸ/ ã䜿ã£ãŠã ?æ£èŠè¡šçŸ? ã䜿ã£ãŠããçŸåšè¡ã¯æåŸã«æ€çŽ¢ãããããã§ããã
?æ£èŠè¡šçŸ? ã¯ãããã¡ãå é ã«åããŠæ€çŽ¢ãããããããã¯ã³ãã³ãã«å眮ãããã¢ãã¬ã¹äžŠã³ããããã¡å é ã«è¿ããã®ããé ã«äžŠãã§ããªããšãããªããšããååãèŠããã®ã§ã¯ãªããããšãã°ããããã¡ã®å 容ã
one two three four five
ã§ãããšãïŒçŸåšè¡ããããã«ãã£ãŠãïŒã
> ?three?,?five?p
ã¯ã2 è¡ç®ãã 5 è¡ç®ãŸã§ãæ£ãã衚瀺ãããã
> ?three?,?one?p
ã¯ãšã©ãŒã«ãªãã
ç¹å®ã®æååãå«ãè¡ãè€æ°ãããšãã«ããããã®è¡ããã¹ãŠè¡šç€ºããããšæãããšãããã ãããããããæ£èŠè¡šçŸã«ããã¢ãã¬ã¹æå®ã¯ãããããçšéã§äœ¿ãããšãã§ããªããæ€çŽ¢ã¯å¿ ãæåã®ãããã§æ€çŽ¢ãåæ¢ãããããã®åäœãå€æŽãããªãã·ã§ã³ã®ãããªãã®ã¯ååšããªããããã«ãããããé£ç¶ããŠããªãè€æ°ã®è¡ã衚瀺ããããã®ã³ãã³ãã¯çšæãããŠããªãããã®ç®çãéããããã«ã¯ã次ã«è¿°ã¹ã g ã³ãã³ãã䜿ãã¹ãã§ããã
g ã³ãã³ã
ã³ãã³ãã®äžã§ç¹å¥ãªãã®ã g ã³ãã³ãã§ãããããã¯ãçŽåŸã«æ£èŠè¡šçŸããšããããã«ãã®åŸãã«ã³ãã³ããªã¹ãããšãããšãã§ãããã³ãã³ããªã¹ãäžã®åã³ãã³ãã¯ãæåŸã®ãã®ãé€ããŠãããã¯ã¹ã©ãã·ã¥ïŒæ¹è¡ã§åºåãããŠããªããŠã¯ãªããªããæ£èŠè¡šçŸããããããè¡ã«å¯ŸããŠãã³ãã³ããªã¹ããäžåãã€å®è¡ãããããã ããã³ãã³ããªã¹ãäžã«åã³ g ãå«ããããšã¯ã§ããªãããããã£ãŠã
> 1,10g/dog/p\ p
ã¯ã1 è¡ç®ãã 10 è¡ç®ãŸã§ã®ãªãã§ãdog ãå«ãè¡ãäºåãã€è¡šç€ºããã(äºè¡ã«ããã£ãŠãããããããã¯ããã¯ã¹ã©ãã·ã¥ã§äžã€ã«ã€ãªãã£ããã®ã )ãã³ãã³ããªã¹ãäžã®ã³ãã³ãã¯äžã€ã§ãããŸããªãã®ã§ã
> 1,10g/dog/p
ãšããŠããã°ãäžåãã€è¡šç€ºãããã
ã³ãã³ããªã¹ãã®äžã«æžãã³ãã³ãã¯ãã¢ãã¬ã¹ãå眮ããããšãå¯èœã§ããããããã£ãŠã
> 1,10g/dog/.=
ã¯ã1è¡ç®ãã 10 è¡ç®ãŸã§ã®ãªãã§ãdog ãå«ãè¡çªå·ã衚瀺ããã
ãã¡ããã. 以å€ã®ã¢ãã¬ã¹ãæå®ããããšãã§ãããããšãã°ã
1,10g/dog/5p
ã¯ã1 è¡ç®ãã 10 è¡ç®ãŸã§ã« dog ãå«ãè¡ã®ããåæ°ã ãã5 è¡ç®ã®å 容ã衚瀺ãããããã« dog ãå«ãè¡ã 3 è¡ãã£ããšãããšããŸã£ããåããã®ã 3 ååºåããããïŒãã¶ããã ãããããªããšã¯ãããããªãã§ãããïŒã
g ã³ãã³ãã«å眮ãããã¢ãã¬ã¹ãçç¥ãããå Žåã¯ã1,$ ãããã©ã«ããšããŠäœ¿ãããããããã£ãŠã
> g/dog/p
ã¯ãçŸåšè¡ããããã«ãã£ãŠãããããã¡äžã§ dog ãå«ãè¡ãå é ãããã¹ãŠè¡šç€ºããã
è足ãªããèšã£ãŠãããšãg ã³ãã³ãã«åŸç¶ããæ£èŠè¡šçŸãšãã¢ãã¬ã¹ãæå®ããããã®æ£èŠè¡šçŸãæèäžãã£ããåºå¥ããŠèããããšã ed ç¿åŸã®äžã€ã®éµã§ããã
äºçš®é¡ã®ããªãã¿
äžè¬ã«ãè€æ°ã®ã¢ãã¬ã¹ãæå®ããå Žåã®ããªãã¿ã¯ãã«ã³ãã®ã»ãã«ã»ãã³ãã³ã䜿ãããšãã§ãããããªãã¿ã«ã»ãã³ãã³ã䜿ã£ãå ŽåãåŸç¶ããã¢ãã¬ã¹ã¯å è¡ããã¢ãã¬ã¹ãçŸåšè¡ãšããŠè§£éãããéã«ãããšãããªãã¿ã«ã«ã³ãã䜿ã£ãå Žåãããã¢ãã¬ã¹ã®è§£éã«çšããããçŸåšè¡ã¯ãå è¡ããã¢ãã¬ã¹ã«å·Šå³ãããªãã
äºã€ã®ã¢ãã¬ã¹ãè¡çªå·ã§æå®ãããããªå Žåãè¡çªå·ãæãè¡ã¯çŸåšè¡ããããã«ãããã«äŸåããªãã®ã§ã
> 1,5p > 1;5p
ã®ãµãã€ã¯ããšãã« 1 è¡ç®ãã 5 è¡ç®ãŸã§ã衚瀺ããã«éããªãããããããªãã»ãããæå®ããå Žåã«ã¯ããªãã¿ã«ã»ãã³ãã³ã䜿ãæå³ãåºãŠãããïŒã¢ãã¬ã¹ã«ãªãã»ããã ããæå®ãããå ŽåãçŸåšè¡ãåºæºãšãªãããã§ããïŒ
ãããã¡ã®äžè¡ç®ã«çŸåšè¡ããããšããŠã
> 3,+1p
ãšãããšãInvalid address ãšãããšã©ãŒã«ãªããããã¯ãäºã€ç®ã®ã¢ãã¬ã¹ã¯ãªãã»ããã ãã§åºæºãšãªãã¢ãã¬ã¹ãæ瀺ãããŠããªãã®ã§ã.+ ã€ãŸãçŸåšè¡ã®æ¬¡ã®è¡ãšè§£éãããã®ã§ãããçŸåšè¡ã 1 ã ã£ãã®ã§ãçµå±ã3,2 ãšããããåŸãªãç¯å²ãæå®ãããããšã«ãªã£ãã®ã§ãããããã«æ¯ã¹ãŠã
3;+1p
ãšãããšãäºã€ç®ã®ã¢ãã¬ã¹ã«ãšã£ãŠã®çŸåšè¡ã¯ãå è¡ããã¢ãã¬ã¹ãæã 3 è¡ç®ãšããããšã«ãªãã®ã§ããã®ã³ãã³ã㯠3 è¡ç®ãã 4 è¡ç®ãŸã§ã衚瀺ããããšã«ãªãã
ã¢ãã¬ã¹ã«æ£èŠè¡šçŸã䜿ããããªå Žåã«ãããã®ã»ãã³ãã³ã¯å€§å€æçšã§ããã
p ã³ãã³ãã¯ãäºã€ã®ã¢ãã¬ã¹ãæåŸ ããŠãããäžã€ä»¥äžæå®ãããå ŽåãåŸãããäºã€ã®ã¢ãã¬ã¹ã ãã䜿çšããããšåè¿°ãããp ã³ãã³ãã§ã¢ãã¬ã¹ãäžã€æå®ããå Žåãã¢ãã¬ã¹ã®åºåãã«ã«ã³ãã䜿ãéããæåã®ã¢ãã¬ã¹ã¯æå³ãæããªããããããåºåãã«ã»ãã³ãã³ã䜿ããªãã°ã話ã¯éã£ãŠããã
chapter1 section1 ïŒç¬¬ 1 ç« ç¬¬ 1 ç¯ã®å å®¹ïŒ section2 ïŒç¬¬ 1 ç« ç¬¬ 2 ç¯ã®å å®¹ïŒ section3 ïŒç¬¬ 1 ç« ç¬¬ 3 ç¯ã®å å®¹ïŒ chapter2 section1 ïŒç¬¬ 2 ç« ç¬¬ 1 ç¯ã®å å®¹ïŒ section2 ïŒç¬¬ 2 ç« ç¬¬ 2 ç¯ã®å å®¹ïŒ section3 ïŒç¬¬ 1 ç« ç¬¬ 2 ç¯ã®å 容ïŒ
ãšããå 容ã®ãããã¡ã§ãçŸåšè¡ã 1 è¡ç®ã«ãããšãããšã
> /chapter2/;/section2/;/section3/-p
ã¯ã第 2 ç« ç¬¬ 2 ç¯ã®å 容ã衚瀺ãããæåã®ã¢ãã¬ã¹ã¯ãçŸåšè¡ãé²ããã®ã«åœ¹ç«ã£ãŠããã®ã ããããåºåãã«ã«ã³ãã䜿ã£ããªãã°ã第 1 ç« ç¬¬ 2 ç¯ã®å 容ã衚瀺ãããŠããŸãã ããã
ããããã¢ãã¬ã¹ã®æå®ã g ã³ãã³ããšäœµçšããã°ããšã«ãããããªãè€éãªæ€çŽ¢ãå¯èœã«ãªãã
å è¿°ããããåŸç¶ããã¢ãã¬ã¹ã¯å è¡ããã¢ãã¬ã¹ãšåãããã以åã®è¡ã瀺ããã®ã§ã¯ãªããŠã¯ãªããªããããã«ã€ããŠã¯ãããªãã¿ã«ã«ã³ãã䜿ã£ãå Žåãšç°ãªãããšããªãã
ããã§ã¯ããäžã€ã ãç°¡åãªäŸãæããŠããããçŸåšè¡ããããã¡ã®äžã®ã»ãã«ãããšãã«ãæ£èŠè¡šçŸã䜿ã£ãã¢ãã¬ã¹æå®ã§å é ããæ¢çŽ¢ããæåã«ãããããè¡ã®è¡çªå·ã衚瀺ããããå Žåã«ã¯ã
1;/dog/=
ã®ããã«ããã°ãããïŒããããã« /dog/= ãšãããªãã°æ£èŠè¡šçŸã«ããæ¢çŽ¢ã¯ãçŸåšè¡ã®æ¬¡ã®è¡ããéå§ãããã ãããïŒ
// ã®å©çš
// ã¯æåŸã«è¡ã£ãæ€çŽ¢ãç¹°ãè¿ããšããã¥ã¢ã«ã«ãããããã¯ãæåŸã«æžããæ£èŠè¡šçŸãããäžåºŠæã€æéãçãã ãã®ãã®ã§ããã
ã¢ãã¬ã¹æå®ã«ããã䜿ãããšãèããŠã¿ããšãçŸåšè¡ã¯åã®æ€çŽ¢ã®ãšãããå€ãã£ãŠããå¯èœæ§ãããã®ã§ããããã¡ã®å 容ã«å€æŽããªããšããŠã // ã«ããååãšåäžã®ã¢ãã¬ã¹ãåŸããããšã¯éããªãã
ãã® // ãšããç¥èšã¯ãã¢ãã¬ã¹æå®ã®ããã«ã䜿ããããg ã³ãã³ãã«åŸç¶ããæ£èŠè¡šçŸãšããŠã䜿ããããããŠãååã®æ€çŽ¢ããã¢ãã¬ã¹æå®äžã®æ£èŠè¡šçŸã ã£ãå Žåã¯ãã®å 容ããg ã³ãã³ãã«åŸç¶ããæ£èŠè¡šçŸã ã£ãå Žåã¯ãã¡ãã®å 容ãããã®åŸã«äœ¿ããã // ã«ãã£ãŠåçŸãããã
s ã³ãã³ã
ed ã«ãããŠã³ãã³ãã®å¯Ÿè±¡ãšãªããã®ã¯åžžã«è¡åäœã§ãããããäžæåã®ã¿ã€ããã¹ãä¿®æ£ããã«ãããã®è¡å šäœã察象ã«ãã眮æã³ãã³ããæã£ãŠããå¿ èŠãããã眮æçšã® s ã³ãã³ãã¯ãããããçšéã«ãã䜿ãããã
s ã³ãã³ãã¯ãs/old/new/ ã®åœ¢ããšããããšãã°ã
> 1,10s/old/new/
ã¯ã1 è¡ç®ãã 10 è¡ç®ã®ç¯å²ã«ãããŠãåè¡ã®æåã«åºçŸãã old ã new ã«çœ®æããã
åè¡ã«åºçŸãããã¹ãŠã® old ã new ã«çœ®æããããã«ã¯ã
> 1,10s/old/new/g
ã®ããã«ãg ãµããã£ã¯ã¹ïŒæ¥å°ŸèŸïŒãå ããããã® g ã¯ããããŸã§ã s ã³ãã³ãã®ãµããã£ã¯ã¹ã§ãããå è¿°ããã³ãã³ãã® g ãšã¯ãŸã£ããå¥ç©ã§ããã
s ã³ãã³ãã®ãµããã£ã¯ã¹ãšããŠèªç¶æ°ãçšããããšãã§ãããããã«ãã£ãŠããã®è¡ã«ãããŠäœåç®ã«ãããããéšåã«çœ®æãåãããããæå®ã§ããã
s ã³ãã³ãã¯ãäºã€ã®ã¢ãã¬ã¹ãå眮ãããããšãæåŸ ããŠãããããã¢ãã¬ã¹ãäžã€ãäžããããªãã£ãå Žåã.,. ãäžãããããšè§£ããã眮æã¯çŸåšè¡ã®ã¿ã«å¯ŸããŠè¡ãããã
ãã®ä»
u ã§çŽåã«å®è¡ããã³ãã³ãã®ã¢ã³ãã¥ã
è¡çªå·ã€ãã®è¡šç€ºïŒnïŒã
åé€ïŒdïŒã移åïŒmïŒãã³ããŒïŒtïŒãè¡ã®é£çµïŒjïŒãè¡ã«å¯ŸããããŒã¯ïŒjïŒãè¡çªå·ã€ãã®è¡šç€ºïŒnïŒãæåŸã®çœ®æã®ç¹°ãè¿ãïŒsïŒã
ãšã©ãŒã¡ãã»ãŒãžè¡šç€ºã®ãã°ã«ïŒHïŒãæåŸã®ãšã©ãŒã¡ãã»ãŒãžã®è¡šç€ºïŒhïŒãã³ãã³ãããã³ãã衚瀺ã®ãã°ã«ïŒPïŒã
r ã¯æå®ããããã¡ã€ã«ãæå®ããè¡ã®åŸãã«è¿œå ããw ã¯ãã¡ã€ã«ãžã®æžãåºããe ã¯ãã¡ã€ã«ãèªã¿èŸŒãã
r! ã«ã€ã¥ããŠã·ã§ã«ã³ãã³ããå ¥åãããšããã®ã³ãã³ããã·ã§ã«ã§å®è¡ãããŠãæšæºåºåãæå®è¡ã®åŸãã«èªã¿èŸŒãŸããã
q 㧠ed ã¯çµäºãQ ã§ç¡æ¡ä»¶ã«çµäºãããCrl c ã§åœä»€ã®ãã£ã³ã»ã«ã§ãããå ¥åã¢ãŒãã«ããã°ãããããŸã³ãã³ãã¢ãŒãã«æããã
ãã®ã»ãè²ã :-)
ed ãšæ¥æ¬èª
ãã®åé¡ã«ã€ããŠã¯ãç§ã¯ããŸãç解ããŠããªãããã ããã«å®¹æã«èŠ³å¯ã§ããç¹ã ããæžããŠãããã
åœç¶ãªãããed ãèµ·åããã¿ãŒããã«ãæ¥æ¬èªãããŸãæ±ããå¿ èŠããããç§ã® Linux æ©ã®ãã±ãŒã«ã¯ ja_JP.eucJP ã§ãgnome-terminal 2.4.2 ãš kterm 6.2.0.ext02 ãšãå ¥ã£ãŠãããkterm ã»ãããæ¥æ¬èªãããããŸãæ±ãããšãã§ããã®ã§ãed ã§æ¥æ¬èªãæ±ããšãã¯ããã¡ããå©çšããŠãããïŒããšãã° gnome-terminal ã¯ãè¡é ã« 2 ãã€ãã¹ããŒã¹ããããšã衚瀺ç¶æ³ãäžå®å®ã«ãªã£ããããïŒ
ããšã®åé¡ã¯ãed ãã®ãã®ã«ã€ããŠã§ãed ãèªåãåããŠããç°å¢ã®ãã±ãŒã«ãã©ã®ããã«çãããããŸãçãããããã«ã³ã³ãã€ã«ãããŠããããšããããšã§ãããç§ã¯ GNU ed version 0.2 ã䜿ã£ãŠãããããšãããããã¯ã³ã³ãã€ã«æã« locale.h ãã€ã³ã¯ã«ãŒãããŠããã
è©Šãã« ed ã§æ¥æ¬èªã䜿ã£ãŠã¿ããšãããªã挢åãªã©ã® 2 ãã€ãæåãæ£èŠè¡šçŸã®ã¡ã¿ãã£ã©ã¯ã¿ . ïŒããªãªãïŒã«ãã£ãŠæ£ããäžæåãšããŠèªèãããŠããããããã[ ] ã䜿ã£ãæåã¯ã©ã¹ã®æå®ã§ã- ã䜿ãç¯å²ãæå®ããå ŽåïŒããšãã° [ã-ã]ïŒãåŠå®æåã¯ã©ã¹ãçšããå Žåã«ã¯ãããŸããããªãã£ãã
äœè«ãªãããç§ã®ç°å¢ã«ãããŠé¢çœãããšã芳å¯ã§ããã®ã¯ãed ã®å ¥åã¢ãŒãã«ãã㊠2 ãã€ãæåãå ¥åæã«ãããã¯ã¹ããŒã¹ã䜿ã£ããšãã§ãããããšãã°ãå ¥åã¢ãŒãã§å¹³ä»®åã®ããããå ¥åããŠãããã¯ã¹ããŒã¹ãäžåæŒããšããããã®å³ååã ããæ¶ãããããã«ããã§ããããããäžåºŠæã¡èŸŒãã§ããã¯ãããã¯ã¹ããŒã¹ãäžåæŒããã³ãã³ãã¢ãŒãã«æ»ã£ãŠ p ã³ãã³ãã§ãã®è¡ãèŠãŠã¿ããšãããããäžã€è¡šç€ºããããããããäºã€äœ¿ã£ãŠããããå ¥åã§ããããã§ããã
ããããã«ãç§ã®ç°å¢ã§ã¯ãå ¥åã¢ãŒãæã®ããã¯ã¹ããŒã¹ã¯ãçŽåã®æåã 1 ãã€ãæåã§ããããš 2 ãã€ãæåã§ããããš 1 ãã€ãã¶ãåé€ããã®ã ãlïŒãšã«ïŒã³ãã³ãã§ããããèŠããš \244\242ãããããèŠããš \244\244 ã§ããïŒããã¯ããããããã® EUC è¡šçŸã 8 é²æ°ã§ããããããã®ãªãïŒããããã®åå 1 ãã€ããäºã€ã€ãªãããšãããã«ãªãã®ã ã
é察話ç䜿ãæ¹
sed ã§ã¯é£ããã ed ã§ã¯ç°¡åã ãšããçš®é¡ã®ç·šéäœæ¥ããããed ãã³ãã³ãã©ã€ã³ããé察話çã«å©çšãããããšãããã
ed 㯠sed ãšã¡ããç·šé察象ãæšæºå ¥åããåãåãããšãã§ããªããç·šé察象ããã¡ã€ã«ã«ä¿åããã³ãã³ãã©ã€ã³ïŒããã㯠w ã³ãã³ãïŒã§ãã®ãã¡ã€ã«åãäžããã»ãã¯ãªããed ãæšæºå ¥åããåãåãã®ã¯ãã³ãã³ãã§ããããšã©ãŒã¡ãã»ãŒãžã¯æšæºãšã©ãŒã«éãããã-s ãªãã·ã§ã³ïŒãã ã® - ãåãïŒã¯ãããçš®ã®ã¡ãã»ãŒãžãæšæºãšã©ãŒã«åºãã®ãææ¢ããããªããH ã³ãã³ãã«ããåºåããããšã©ãŒã¡ãã»ãŒãžããæšæºãšã©ãŒã«éããããïŒGNU ed ver0.2ïŒ
$ cat input.txt the first line the second line the third line $ cat command.txt 1p 3p $ /bin/ed -s input.txt < command.txt > output.txt $ cat output.txt the first line the third line
段èœå æ¹è¡ã®åé€
ããã«äžè¡ã®è¡æ°ãäžå®ã®ç¯å²ã«åããããã«ã段èœã®éäžã§æ¹è¡ããããŠããåçš¿ãããããããã段èœå ã®æ¹è¡ãåé€ããããšãèããŠã¿ãã
ããããããäžè¡åæ°ã®èšå®æ¹æ³ãç¥ããªãã¯ãŒããå©çšè ã«ããåçš¿ã§ãã£ããªãããã¶ã段èœé ã®åäžãããã¯ã€ãã¹ããŒã¹ãçšããŠè¡šçŸããŠããã ãããããããåçš¿ãåŠçããã«ã¯ã
$;/^[ ã]/,$v/^[ ã]/-,.j
ã§äºè¶³ãããïŒãã㧠[ ã] ã®äžèº«ã¯ã1 ãã€ããš 2 ãã€ãã®ãã¯ã€ãã¹ããŒã¹ãäžåãã€å ¥ã£ãŠãã£ãŠããïŒã翻蚳ãããšããŸãæçµè¡ã®æ¬¡ã®è¡ïŒãããã¡ã®äžçªäžã®è¡ïŒããã¹ããŒã¹ã§å§ãŸãè¡ãããããŠããããã®è¡ããæçµè¡ãŸã§ã®ãã¡ã1 ãã€ãããã㯠2 ãã€ãã®ç©ºçœã«ãã£ãŠå§ãŸããªãè¡ã«ã€ããŠã¯ããã®åè¡ãšãã®è¡ãé£çµããããšããæå³ã§ããã空çœã§å§ãŸãè¡ãã²ãšã€ããªããã°ãNo Match ãšã©ãŒã«ãªãã
äžæ¹ãã¡ãŒã«æ¬æã LaTeX ã®åçš¿ã®ããã«ã空è¡ããã£ãŠæ®µèœã®å¢ãšãªããããªãã®ã§ã¯ã
$;/./+,$v/^$/-,.j
ãšããã°ãçšã足ãããããã¯ãããŸãæçµè¡ã®æ¬¡ã®è¡ïŒãããã¡ã®äžçªäžã®è¡ïŒãããäœãæåãå«ãè¡ããããããã®æ¬¡ã®è¡ããæçµè¡ãŸã§ã«å¯ŸããŠããã空è¡ã§ãªãè¡ãããã°ããã®åè¡ãšãã®è¡ãå䜵ããããšç¿»èš³ããããšãã§ããããã ãããããã¡ã«äžè¡ãããªãå Žåã¯ãã¢ãã¬ã¹ã»ãšã©ãŒã«ãªãã
ãããã«äŒŒãããšã sed ã§ããããšãããš ãããªå ·åã«ãªããsed 㯠ed ãšéããé»ã£ãŠå ¥åå šäœãä¿æããŠãããããªãããã¡ãæããªãã®ã§ããŒã«ãã¹ããŒã¹ãžã®ãããã¡ãªã³ã°ãæ瀺çã«è¡ã£ãŠããã
diff ãš ed
diff ã¯äºã€ã®ãã¡ã€ã«ãæ¯èŒãããã-e ãªãã·ã§ã³ã䜿ããšãæ¯èŒããçµæã ed ãã³ãã³ãã»ã¹ã¯ãªãããšããŠèªãããããªåœ¢ã§åºåããããšãã§ããïŒäœ¿ãããã®ã¯ãa, c, d åã³ãã³ãïŒãed ã patch ã®ããã«çšããããšãã§ããããã§ãããå®éããã㯠patch ãäœããããŸã§å©çšãããŠããããã ã
$ cat old.txt This is old. $ cat new.txt This is new. $ diff -e old.txt new.txt > diff.txt $ cat diff.txt 2c new. . $ (cat diff.txt; echo '1,$p') | /bin/ed -s old.txt This is new.
ledit ãš ed
ed ã¯ãã©ããªãšãã§ã䜿ããããã«ãš readline ãªããŠèŠªåãªãã®ã¯äœ¿ã£ãŠããªããã ãããa ã³ãã³ãã§å ¥åäžã«ãã®è¡ã®ãã§ã«æã£ããšããã«ã«ãŒãœã«ãæ»ããŠåé€ãæ¿å ¥ããããã以åã«æã£ãã³ãã³ããåŒã³åºããŠãããå°ãçŽããŠå®è¡ããããšã¯ã§ããªããããã ledit ãšãããã®ããããæšæºå ¥åãæšæºåºåã«åºãã ãã ãããã®éã« readline ã䜿ã£ãç·šéãããããŠããããããŒãã€ã³ãã£ã³ã°ã¯ãããã Emacs åŒã ãæ®å¿µãªããæ¥æ¬èªã䜿ãããšã¯ã§ããªããã©ã
$ ledit ed
ed ã§åèªåž³ãäœã
ed ã®ç©æ¥µçãªå©çšã®ä»æ¹ã¯ãªããã®ããšèããŠããŠãåèªåž³ãç·šéããã®ã«åå€åããŠãããã ãšæãåœãã£ããåèªåž³ã¯äžè¡ãã€ããŒã¿ãç¬ç«ããŠããã®ã§ãã¹ã¯ãªãŒã³ãšãã£ã¿ã§ãªããŠãååå®çšã«ãªãããã ã
ããã«ãåèªåž³ã¯æ€çŽ¢ã®å¿ èŠæ§ãé«ãã®ã§ãã³ãã³ãã¢ãŒããšå ¥åã¢ãŒãããã ed ã®æŽ»èºããå Žé¢ãå€ãã§ããããããšãã°ãä»ãŸã§å ¥åããåèªãæ€çŽ¢ãããšãã«ã ed ã䜿ããšå¹žããªæ°åãå³ããããããšãã° cat ãšããåèªãä»ãŸã§èª¿ã¹ããã©ããç¥ããããšãã«ãããç°¡åã« /cat ãšã ãæãŠã°ãããã¡ãã£ãšããããŒã¿ããŒã¹æ°åãå³ãããã
ãŸããç°¡åã«åèªåž³ã®æ§é ã決ããŠãããšäŸ¿å©ã«ã¡ãããªãã以äžãã®äžäŸã
---By the Ionian Sea---+ 75+ --ch10 @2005-12-21 carry away å°è±¡ãåãã uncouth ç²é㪠demeanour ç«ã¡å± ãµããŸã âŠâŠ 76+ exclamation æå querulous /kw'erul\as/æçŽã£ãœã âŠâŠ drift 倧æ hit the drift of by dint of sth. ãã®åã«ãã revile ã®ã®ãã 77+ kith and kin 芪é¡çžè @2005-12-22 stone-dead å šãæ¯ã®çµ¶ãã take hold upon sb. èžãæ〠âŠâŠ scenic /si:nik/ èå± ã®ãã㪠fall foul of sb. åœããæ£ãã @2005-12-25 ensue ç¶ãèµ·ãã access (å») çºäœ âŠâŠ expectorate: cough or spit out (phelgm) from the throat or lungs inmate: å容è hosterly: (archaic or humorous) in or pub ---+
å®éã®äœ¿çšäŸã¯ããšãã°ä»¥äžã®ããšãã
# ã·ã§ã«ãã ed ãèµ·åãããã³ããã > ã«ããŠãã $ ed -p '> ' words.txt 1072 > # 以äžã·ã£ãŒãã§å§ãŸãè¡ã¯ã³ã¡ã³ãã > # èµ·åæã«è¡šç€ºãããã®ã¯ãã€ãæ°ã > # èµ·åæã®çŸåšè¡ã¯æçµè¡ã > # H ã§ãšã©ãŒã¡ãã»ãŒãžã衚瀺ããããèšå® > H > # ã©ããªæ¬ã®äœç« ãå匷ããŠãããã ã£ãã > g?^-?p ---By the Ionian Sea---+ --ch10 ---+ > # äœããŒãžãèªãã§ãã£ããã ã£ã > # ( ? ? ã§ãããã æ£èŠè¡šçŸã¯æé ãžåããŠæ€çŽ¢ããã > # ãŸããããŒãžçªå·ã瀺ãè¡ã¯ + ã§çµãã£ãŠãã ) > ?+$?p 77+ > # ã©ã®åèªãŸã§åŒããããªãæåŸ 5 è¡ãèŠãŠã¿ããã > $-5,$p bustle: move energetically or noisily *phlegm /flem/ ç° expectorate: cough or spit out (phelgm) from the throat or lungs inmate: å容è hosterly: (archaic or humorous) in or pub ---+ > # ãŸãä»æ¥ã®æ¥ä»ãæžã蟌ãã > $-r !date +@\%Y-\%m-\%d 12 > # æ¥ä»ã¶ã 12 ãã€ããæ¿å ¥ãããã > # ã§ã¯ä»æ¥ã®å匷ã ã > # subside ã£ãŠåã«èª¿ã¹ãã㪠> /subside ? No match > # 調ã¹ãŠãªã㪠> # subside ããããã«æžã蟌ãã > $i subside ïŒç±ãïŒãããã . > # ãã£ãšããããã次ã®ããŒãžã > a 78+ . > # qualm ãæžã蟌ãã > a qualm (a) feeeling doubt or unease about one's behaver . > # 綎ãã¯ã ããããã¶ããã§ãã¯ããã > .w !nkf -w | aspell -l feeeling 56 > # 説ææäžã§ feeling ã® e ãäžåå€ãã£ãã > # (56 ãšããã®ã¯ ispell ãžã®åºåãã€ãæ°) > # ãã£ããçŽããŠããã > s/eee/ee/ > # ã²ãšãŸããä¿å > w 1143 > # ãã¡ã€ã«ã®ãµã€ãºã¯ 1143 ãã€ãã ã£ãŠã > # > # åã«ãã£ãæ¥ã«å匷ããåèªã埩ç¿ããšãã > ?^@?;?^@?;/^@/-p @2005-12-25 ensue ç¶ãèµ·ãã access (å») çºäœ lank ã²ããé·ã âŠâŠ > # ä»æ¥èª¿ã¹ãåèªãå°å·ããšãã > $;?^@?;$w !mpage -1 | lpr > 76 > # ã§ãçµäº > q $ # ã·ã§ã«ã«æ»ã£ãŠããŸããããã§ããããã§ããã