搜索墙首页  编程技术  java  asp  ajax  php  c/c#/c++  数据库  oracle  mysql  db2  操作系统  windows  linux  股吧
首页 > 操作系统 > linux
 1         
1楼  cwking726 2009-12-07

# nl datafile
     1  northwest       NW      Charles Main    3.0     .98     3       34
     2  western         WE      Sharon Gray     5.3     .97     5       23
     3  southwest       SW      Lewis Dalsass   2.7     .8      2       18
     4  southern        SO      Suan Chin       5.1     .95     4       15
     5  southeast       SE      Patricia Hemenway       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
      
# cat datafile
northwest       NW      Charles Main    3.0     .98     3       34
western         WE      Sharon Gray     5.3     .97     5       23
southwest       SW      Lewis Dalsass   2.7     .8      2       18
southern        SO      Suan Chin       5.1     .95     4       15
southeast       SE      Patricia Hemenway       4.0     .7      4       17
eastern         EA      TB Savage       4.4     .84     5       20
northeast       NE      AM Main Jr.     5.1     .94     3       13
north           NO      Margot Weber    4.5     .89     5       9
central         CT      Ann Stephens    5.7     .94     5       13
# more datafile
northwest       NW      Charles Main    3.0     .98     3       34
western         WE      Sharon Gray     5.3     .97     5       23
southwest       SW      Lewis Dalsass   2.7     .8      2       18
southern        SO      Suan Chin       5.1     .95     4       15
southeast       SE      Patricia Hemenway       4.0     .7      4       17
eastern         EA      TB Savage       4.4     .84     5       20
northeast       NE      AM Main Jr.     5.1     .94     3       13
north           NO      Margot Weber    4.5     .89     5       9
central         CT      Ann Stephens    5.7     .94     5       13
datafile: END
#
# sed '/^eastern/i\       
> new line begin\
> ***************' datafile
northwest       NW      Charles Main    3.0     .98     3       34
western         WE      Sharon Gray     5.3     .97     5       23
southwest       SW      Lewis Dalsass   2.7     .8      2       18
southern        SO      Suan Chin       5.1     .95     4       15
southeast       SE      Patricia Hemenway       4.0     .7      4       17
new line begin
***************
eastern         EA      TB Savage       4.4     .84     5       20
northeast       NE      AM Main Jr.     5.1     .94     3       13
north           NO      Margot Weber    4.5     .89     5       9
central         CT      Ann Stephens    5.7     .94     5       13
# sed  '/eastern/{n;s/AM/Archie/;}' datafile
northwest       NW      Charles Main    3.0     .98     3       34
western         WE      Sharon Gray     5.3     .97     5       23
southwest       SW      Lewis Dalsass   2.7     .8      2       18
southern        SO      Suan Chin       5.1     .95     4       15
southeast       SE      Patricia Hemenway       4.0     .7      4       17
eastern         EA      TB Savage       4.4     .84     5       20
northeast       NE      Archie Main Jr. 5.1     .94     3       13
north           NO      Margot Weber    4.5     .89     5       9
central         CT      Ann Stephens    5.7     .94     5       13
# sed -e '/northeast/h' -e '$g' datafile
northwest       NW      Charles Main    3.0     .98     3       34
western         WE      Sharon Gray     5.3     .97     5       23
southwest       SW      Lewis Dalsass   2.7     .8      2       18
southern        SO      Suan Chin       5.1     .95     4       15
southeast       SE      Patricia Hemenway       4.0     .7      4       17
eastern         EA      TB Savage       4.4     .84     5       20
northeast       NE      AM Main Jr.     5.1     .94     3       13
north           NO      Margot Weber    4.5     .89     5       9
central         CT      Ann Stephens    5.7     .94     5       13
northeast       NE      AM Main Jr.     5.1     .94     3       13
# sed -e '/northeast/h' -e '/CT/{g;}' datafile
northwest       NW      Charles Main    3.0     .98     3       34
western         WE      Sharon Gray     5.3     .97     5       23
southwest       SW      Lewis Dalsass   2.7     .8      2       18
southern        SO      Suan Chin       5.1     .95     4       15
southeast       SE      Patricia Hemenway       4.0     .7      4       17
eastern         EA      TB Savage       4.4     .84     5       20
northeast       NE      AM Main Jr.     5.1     .94     3       13
north           NO      Margot Weber    4.5     .89     5       9
northeast       NE      AM Main Jr.     5.1     .94     3       13
# sed -e '/northeast/h' -e '/CT/{G;}' datafile
northwest       NW      Charles Main    3.0     .98     3       34
western         WE      Sharon Gray     5.3     .97     5       23
southwest       SW      Lewis Dalsass   2.7     .8      2       18
southern        SO      Suan Chin       5.1     .95     4       15
southeast       SE      Patricia Hemenway       4.0     .7      4       17
eastern         EA      TB Savage       4.4     .84     5       20
northeast       NE      AM Main Jr.     5.1     .94     3       13
north           NO      Margot Weber    4.5     .89     5       9
central         CT      Ann Stephens    5.7     .94     5       13
northeast       NE      AM Main Jr.     5.1     .94     3       13
# sed -e '/northeast/h' -e '$g' datafile  
northwest       NW      Charles Main    3.0     .98     3       34
western         WE      Sharon Gray     5.3     .97     5       23
southwest       SW      Lewis Dalsass   2.7     .8      2       18
southern        SO      Suan Chin       5.1     .95     4       15
southeast       SE      Patricia Hemenway       4.0     .7      4       17
eastern         EA      TB Savage       4.4     .84     5       20
northeast       NE      AM Main Jr.     5.1     .94     3       13
north           NO      Margot Weber    4.5     .89     5       9
central         CT      Ann Stephens    5.7     .94     5       13
northeast       NE      AM Main Jr.     5.1     .94     3       13
# sed -e '/northeast/h' -e '$G' datafile
northwest       NW      Charles Main    3.0     .98     3       34
western         WE      Sharon Gray     5.3     .97     5       23
southwest       SW      Lewis Dalsass   2.7     .8      2       18
southern        SO      Suan Chin       5.1     .95     4       15
southeast       SE      Patricia Hemenway       4.0     .7      4       17
eastern         EA      TB Savage       4.4     .84     5       20
northeast       NE      AM Main Jr.     5.1     .94     3       13
north           NO      Margot Weber    4.5     .89     5       9
central         CT      Ann Stephens    5.7     .94     5       13
northeast       NE      AM Main Jr.     5.1     .94     3       13
# nl datafile
northwest       NW      Charles Main    3.0     .98     3       34
western         WE      Sharon Gray     5.3     .97     5       23      23
      
southwest       SW      Lewis Dalsass   2.7     .8      2       18      18
southern        SO      Suan Chin       5.1     .95     4       15      15
southeast       SE      Patricia Hemenway       4.0     .7      4       17   
  17
eastern         EA      TB Savage       4.4     .84     5       20      20
northeast       NE      AM Main Jr.     5.1     .94     3       13      13
north           NO      Margot Weber    4.5     .89     5       9       9
central         CT      Ann Stephens    5.7     .94     5       13      13
#vi sedding2
1 /western/,/southeast/{
2 /^ *$/d                            
3 /Suan/{h;d;}
}
4 /Ann/g
5 s/TB \(Savage\)/Thomas \1/
注:2删除空行
    4匹配模式Ann,g将暂存缓冲区内的行复制到模式缓冲区里,从而覆盖模式缓冲区的
   内容
# sed -f sedding2 datafile
northwest       NW      Charles Main    3.0     .98     3       34
western         WE      Sharon Gray     5.3     .97     5       23
southwest       SW      Lewis Dalsass   2.7     .8      2       18
southeast       SE      Patricia Hemenway       4.0     .7      4       17
eastern         EA      Thomas Savage   4.4     .84     5       20
northeast       NE      AM Main Jr.     5.1     .94     3       13
north           NO      Margot Weber    4.5     .89     5       9
southern        SO      Suan Chin       5.1     .95     4       15
# sed 's/...$//' datafile
northwest       NW      Charles Main    3.0     .98     3
western         WE      Sharon Gray     5.3     .97     5
southwest       SW      Lewis Dalsass   2.7     .8      2
southern        SO      Suan Chin       5.1     .95     4
southeast       SE      Patricia Hemenway       4.0     .7      4
eastern         EA      TB Savage       4.4     .84     5
northeast       NE      AM Main Jr.     5.1     .94     3
north           NO      Margot Weber    4.5     .89    
central         CT      Ann Stephens    5.7     .94     5
# sed 's/....//' datafile
hwest   NW      Charles Main    3.0     .98     3       34
ern             WE      Sharon Gray     5.3     .97     5       23
hwest   SW      Lewis Dalsass   2.7     .8      2       18
hern    SO      Suan Chin       5.1     .95     4       15
heast   SE      Patricia Hemenway       4.0     .7      4       17
ern             EA      TB Savage       4.4     .84     5       20
heast   NE      AM Main Jr.     5.1     .94     3       13
h               NO      Margot Weber    4.5     .89     5       9
ral             CT      Ann Stephens    5.7     .94     5       13
# sed 's/^....//' datafile
hwest   NW      Charles Main    3.0     .98     3       34
ern             WE      Sharon Gray     5.3     .97     5       23
hwest   SW      Lewis Dalsass   2.7     .8      2       18
hern    SO      Suan Chin       5.1     .95     4       15
heast   SE      Patricia Hemenway       4.0     .7      4       17
ern             EA      TB Savage       4.4     .84     5       20
heast   NE      AM Main Jr.     5.1     .94     3       13
h               NO      Margot Weber    4.5     .89     5       9
ral             CT      Ann Stephens    5.7     .94     5       13
 1         
您的发言将按有关规定都会存档,您须为所发表后果负责,请您遵纪守法并注意语言文明。
标题:sed学习笔记
热门关注
标题回复点击
d7se77dy/77dy电影. 77dy是77dy宽频和77dy1331673
黄网最新地址0903
IPP2P模块修改版,最新0.99.16440828
zeh 4.p patch on RHEL 30744
将 Puppy Linux 4.00 安装在U盘里 打造随身系统2695
Apache 超全0689
gcc glibc kernel 版本兼容性 reference0684
[保留]7667
d7se77dy/77dy电影. 77dy是77dy宽频和77dy156650
linux 有啥低级格式化硬盘的软件1644
搜索墙@2009 www.pkwall.com all rights reserved QQ:276471788 [京ICP备09111534号]
声明:本站部分数据来源于网络,仅供参考,如有版权问题,请联系我们,我们将及时删除!转载本站请注明来源