- 论坛徽章:
- 0
|
文本输出的是对的 ,终端直接显示的不对 。实例1如下
[tianbc@localhost chap03]$ 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
[tianbc@localhost chap03]$ sed '/west/,/east/s/^/**sdfds**/' datafile //从第一个符合west模式 到 第一个 符合 east模
//式的行之间 所有行首添加为**sdfds**,结果符合
**sadfa**northwest NW Charles Main 3.0 .98 3 34
**sadfa**western WE Sharon Gray 5.3 .97 5 23
**sadfa**southwest SW Lewis Dalsass 2.7 .8 2 18
**sadfa**southern SO Suan Chin 5.1 .95 4 15
**sadfa**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
[tianbc@localhost chap03]$ sed '/west/,/east/s/$/**sdfds**/' datafile //跟上一个类似只是换成$应该是行尾。结果如
//下 ,不符合
**sadfa** NW Charles Main 3.0 .98 3 34
**sadfa**WE Sharon Gray 5.3 .97 5 23
**sadfa** SW Lewis Dalsass 2.7 .8 2 18
**sadfa**SO Suan Chin 5.1 .95 4 15
**sadfa** 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
下面是 文本 输出的,命令后 加了个 >a
northwest NW Charles Main 3.0 .98 3 34
**sadfa**
western WE Sharon Gray 5.3 .97 5 23
**sadfa**
southwest SW Lewis Dalsass 2.7 .8 2 18
**sadfa**
southern SO Suan Chin 5.1 .95 4 15
**sadfa**
southeast SE Patricia Hemenway 4.0 .7 4 17
**sadfa**
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
[ 本帖最后由 baidianniupi 于 2008-7-24 14:25 编辑 ] |
|