LinuxÒÁµéÔ°ÂÛ̳'s Archiver

walkright ·¢±íÓÚ 2007-8-24 13:23

ÔõÑùʹÓà sed Ìí¼ÓÐУ¿¼±ÓÃ

[root@server buffer_pool]# cat -n testa
     1
     2  c=0
     3  b=2
     4  a=0
     5  d=1
     6  f=5
[root@server buffer_pool]# cat -n test.sh
     1  #!/bin/sh
     2
     3  cat -n testa
     4
     5  for((i=0; i<$*; i++))
     6  do
     7      sed "///" testa
     8  done
     9
    10  cat -n testa
[root@server buffer_pool]# sh test.sh 5

ÎÒÏëʹÓÃÕâ¸ö½Å±¾ÊµÏÖ
[root@server buffer_pool]# cat -n testa
     1
     2  c=0
     3  b=2
     4  a=0
     5  a=1
     6  a=2
     7  a=3
     8  a=4
     9  d=1
    10  f=5


ÇëÎÊÓ¦¸ÃÔõôÓà sed ʵÏÖ £¿

dearvoid ·¢±íÓÚ 2007-8-24 13:32

[quote][font=Courier][color=blue]-(dearvoid@LinuxEden:Forum)-(~/tmp)-
[16167 0][/color] [color=red]; echo $'aa\nbb'
[/color]aa
bb
[color=blue]-(dearvoid@LinuxEden:Forum)-(~/tmp)-
[16167 0][/color] [color=red]; echo $'aa\nbb' | sed -e $'/bb/i\\\ncc'
[/color]aa
cc
bb
[color=blue]-(dearvoid@LinuxEden:Forum)-(~/tmp)-
[16167 0][/color] [color=red]; bye
[/color][/font][/quote]

walkright ·¢±íÓÚ 2007-8-24 13:44

лл£¬
¿ÉÔõô½«Ð޸ı£´æµ½ÎļþÀïÄØ£¿

dearvoid ·¢±íÓÚ 2007-8-24 13:54

[quote][font=Courier][color=blue]-(dearvoid@LinuxEden:Forum)-(~/tmp)-
[16167 0][/color] [color=red]; echo hello world > file
[/color][color=blue]-(dearvoid@LinuxEden:Forum)-(~/tmp)-
[16167 0][/color] [color=red]; cat file
[/color]hello world
[color=blue]-(dearvoid@LinuxEden:Forum)-(~/tmp)-
[16167 0][/color] [color=red]; bye
[/color][/font][/quote]

walkright ·¢±íÓÚ 2007-8-24 13:56

ÓÖѧ»áÁËÁ½µã£¬¶àл°æÖ÷:lol

walkright ·¢±íÓÚ 2007-8-24 13:58

ÎÒÕâÑùдµÄ£¬
    sed -i $"/d=1/i\\\  a=$i" testa
Ò²¿ÉÒÔ±£´æ

dearvoid ·¢±íÓÚ 2007-8-24 14:17

[quote]Ô­ÌûÓÉ [i]walkright[/i] ÓÚ 2007-8-24 13:58 ·¢±í [url=http://www.linuxeden.com/forum/redirect.php?goto=findpost&pid=581868&ptid=158395][img]http://www.linuxeden.com/forum/images/common/back.gif[/img][/url]
ÎÒÕâÑùдµÄ£¬
    sed -i $"/d=1/i\\\  a=$i" testa
Ò²¿ÉÒÔ±£´æ [/quote]
good :)

li-jiahuan ·¢±íÓÚ 2007-8-25 13:22

Çë½Ìdearvoid

sed -e $'///' ÖÐµÄ "$"ΪºÎÒ⣿

040410615 ·¢±íÓÚ 2007-10-9 17:28

ÎÒÊǽèÖúÒ»¸öÁÙʱÎļþʵÏÖµÄ:)

dearvoid ·¢±íÓÚ 2007-10-9 18:03

[quote]Ô­ÌûÓÉ [i]li-jiahuan[/i] ÓÚ 2007-8-25 13:22 ·¢±í [url=http://www.linuxeden.com/forum/redirect.php?goto=findpost&pid=581933&ptid=158395][img]http://www.linuxeden.com/forum/images/common/back.gif[/img][/url]
Çë½Ìdearvoid

sed -e $'///' ÖÐµÄ "$"ΪºÎÒ⣿ [/quote]
bash µÄ manual Õâô˵:
[font=Courier][code]
       Words of the form $'string' are treated specially.  The word expands to
       string,  with backslash-escaped characters replaced as specified by the
       ANSI C standard.  Backslash escape sequences, if present,  are  decoded
       as follows:
              \a     alert (bell)
              \b     backspace
              \e     an escape character
              \f     form feed
              \n     new line
              \r     carriage return
              \t     horizontal tab
              \v     vertical tab
              \\     backslash
              \'     single quote
              \nnn   the  eight-bit  character  whose value is the octal value
                     nnn (one to three digits)
              \xHH   the eight-bit character whose value  is  the  hexadecimal
                     value HH (one or two hex digits)
              \cx    a control-x character

       The  expanded  result  is  single-quoted, as if the dollar sign had not
       been present.
[/code][/font]

For example:
[quote][font=Courier][color=black][/color][color=blue]-(dearvoid@LinuxEden:Forum)-(~/tmp)-
[$$=1282 $?=0][/color] [color=red]; echo 'hello\nworld'
[/color][color=black]hello\nworld
[/color][color=blue]-(dearvoid@LinuxEden:Forum)-(~/tmp)-
[$$=1282 $?=0][/color] [color=red]; echo $'hello\nworld'
[/color][color=black]hello
world
[/color][color=blue]-(dearvoid@LinuxEden:Forum)-(~/tmp)-
[$$=1282 $?=0][/color] [color=red]; bye
[/color][color=black][/color][/font][/quote]

[[i] ±¾Ìû×îºóÓÉ dearvoid ÓÚ 2007-10-9 18:05 ±à¼­ [/i]]

li-jiahuan ·¢±íÓÚ 2007-10-9 19:36

͵ѧһÕÐ

dearvoid¶ÔÄÐÈË¿´µÃÕæ×Ðϸ°¡:lol

dearvoid ·¢±íÓÚ 2007-10-9 20:12

[quote]Ô­ÌûÓÉ [i]li-jiahuan[/i] ÓÚ 2007-10-9 19:36 ·¢±í [url=http://www.linuxeden.com/forum/redirect.php?goto=findpost&pid=588714&ptid=158395][img]http://www.linuxeden.com/forum/images/common/back.gif[/img][/url]
dearvoid¶ÔÄÐÈË¿´µÃÕæ×Ðϸ°¡:lol [/quote]
²»½âºÎÒâ :(

fitren ·¢±íÓÚ 2007-10-10 09:29

»Ø¸´ #12 dearvoid µÄÌû×Ó

²»ÊÇ˵"man"Âð£¿ÄѵÀ²»ÊÇÄÐÈË£¿:lol
Å®°æÖ÷µÄ»°¿ÉÄÜÊǷdz£Ï²»¶µÄÓ´~

[[i] ±¾Ìû×îºóÓÉ fitren ÓÚ 2007-10-10 09:30 ±à¼­ [/i]]

Ò³: [1]

Powered by Discuz! Archiver 6.1.0  © 2001-2007 Comsenz Inc.