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

zhanglj ·¢±íÓÚ 2007-2-4 11:36

ÇóÖúse d ÎÊÌâ

СµÜѧϰse d µÄʱºòÓöµ½ÎÊÌâ:
se d ÃüÁîÖÐDºÍd µÄÇø±ð.×ÊÁÏÉÏûÓÐ˵Ã÷,ÎÒÊÔÁ˼¸¸öÃüÁî,¹¦Äܶ¼Ò»Ñù.
ÀýÈç:[root@zhanglj home]# sed '2D' axample
1       northwest       NW      Charles Main    3.0     .98     3       34
3       southwest       SW      Lewis Dalsass   2.7     .8      2       18
4       southern        SO      Suan Chin       5.1     .95     4       15
5       southeast       SE      Patricia Hemen  4.0     .7      4       17
6       eastern         EA      TB Savage       4.4     .84     5       20
7       northeast       NE      AM Main Jr.     5.1     .94     3       13
8       north           No      Margot Weber    4.5     .89     5       9
9       central         CT      Ann Stephens    5.7     .94     5       13
[root@zhanglj home]# sed '2d' axample
1       northwest       NW      Charles Main    3.0     .98     3       34
3       southwest       SW      Lewis Dalsass   2.7     .8      2       18
4       southern        SO      Suan Chin       5.1     .95     4       15
5       southeast       SE      Patricia Hemen  4.0     .7      4       17
6       eastern         EA      TB Savage       4.4     .84     5       20
7       northeast       NE      AM Main Jr.     5.1     .94     3       13
8       north           No      Margot Weber    4.5     .89     5       9
9       central         CT      Ann Stephens    5.7     .94     5       13
´ó¼Ò°ïæ½â´ð.Íò·Ö¸Ðл!

li-jiahuan ·¢±íÓÚ 2007-2-5 11:05

ÏñÂ¥Ö÷ÕâÑùµÄÓ÷¨
d ºÍ D ÊÇûÓÐÇø±ðµÄ

ÕâÀïÓиö½âÊÍ
[url]http://phi.sinica.edu.tw/aspac/reports/96/96005/sed_sec_4.html#4.16[/url]
[quote]
#  º¯”µ…¢”µ D ×î¶àÅäºÏƒÉ‚€Î»Ö·…¢”µ¡£
# º¯”µ…¢”µ D Åc d µÄ±ÈÝ^ÈçÏ :

   1. ®” pattern space ƒÈÖ»ÓÐÒ»ÙYÁÏÐЕr , D Åc d ×÷ÓÃÏàͬ¡£
   2. ®” pattern space ƒÈÓжàÐÐÙYÁÏÐЕr
         1. D ±íʾֻ„h³ý pattern space ƒÈµÚÒ»ÐÐÙYÁÏ ; d „tÈ«„h³ý¡£
         2. D ±íʾˆÌÐЄh³ýáá , pattern space ƒÈ²»Ìí¼ÓÏÂÒ»¹PÙYÁÏ , ¶øŒ¢Ê£ÏµÄÙYÁÏÖØÐˆÌÐÐ sed script ; d „t×xÈëÏÂÒ»ÐÐááˆÌÐÐ sed script¡£
[/quote]

[code]
[0 No.535 huanlf@huanlf ~/study]$ cat txt
1 abc
2 abc
3 abc
4 abc

[0 No.536 huanlf@huanlf ~/study]$ sed ' 2 {N; /abc/d } ' txt
1 abc
4 abc

[0 No.537 huanlf@huanlf ~/study]$ sed ' 2 {N; /abc/D } ' txt
1 abc
3 abc
4 abc

[0 No.538 huanlf@huanlf ~/study]$

[/code]

dearvoid ·¢±íÓÚ 2007-2-5 12:35

Õâ¶ùÓиöÓà sed Ä£Äâ tail µÄÀý×Ó, ÆäÖÐÒ²Óõ½ÁË D ÃüÁî:
[code]
[color=blue]-(dearvoid@LinuxEden:tty3)-(~/void/sed/sample_scripts)-
[4011 0][/color] [color=red]; cat tail_2
[/color]#!/usr/bin/sed -f

1h
2,10 {; H; g; }
$q
1,9d
N
D
[color=blue]-(dearvoid@LinuxEden:tty3)-(~/void/sed/sample_scripts)-
[4011 0][/color] [color=red]; cat file
[/color]15
14
13
12
11
10
9
8
7
6
5
4
3
2
1
[color=blue]-(dearvoid@LinuxEden:tty3)-(~/void/sed/sample_scripts)-
[4011 0][/color] [color=red]; sed -f tail_2 file
[/color]10
9
8
7
6
5
4
3
2
1
[color=blue]-(dearvoid@LinuxEden:tty3)-(~/void/sed/sample_scripts)-
[4011 0][/color] [color=red]; o
[/color][/code]

zhanglj ·¢±íÓÚ 2007-2-8 15:04

¶àл°ßÖñ¡£

Ò³: [1]

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