Next: , Previous: tail, Up: Examples   [Contents][Index]


4.14 ½ÅÊ£¤·¤¿¹Ô¤ò°ì¹Ô¤Ë¤¹¤ë

°Ê²¼¤Ï¡¤N¡¤P¡¤¤½¤·¤ÆD¥³¥Þ¥ó¥É¤ò»ÈÍѤ·¤¿¡¤¤ª¤½¤é¤¯ ¥Þ¥¹¥¿¡¼¤¹¤ë¤Î¤¬ºÇ¤âÆñ¤·¤¤·Ý½ÑŪ¤ÊÎã¤Ç¤¹¡¥

#!/usr/bin/sed -f
h
:b
# On the last line, print and exit
$b
N
/^\(.*\)\n\1$/ {
    # The two lines are identical.  Undo the effect of
    # the n command.
    g
    bb
}
# If the N command had added the last line, print and exit
$b
# The lines are different; print the first and go
# back working on the second.
P
D

¸æÍ÷¤Î¤è¤¦¤Ë¡¤P¤ÈD¤ò»ÈÍѤ·¤ÆÆó¹Ô¤Î¥¦¥£¥ó¥É¥¦¤ò´ÉÍý¤·¤Æ¤¤ ¤Þ¤¹¡¥¤³¤Î¥Æ¥¯¥Ë¥Ã¥¯¤Ï¡¤¹âÅÙ¤Êsed¥¹¥¯¥ê¥×¥È¤Ç¤è¤¯»ÈÍѤµ¤ì¤Þ¤¹¡¥