Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2043055
  • 博文数量: 470
  • 博客积分: 10206
  • 博客等级: 上将
  • 技术积分: 5620
  • 用 户 组: 普通用户
  • 注册时间: 2008-07-03 12:50
文章分类

全部博文(470)

文章存档

2012年(1)

2011年(18)

2010年(47)

2009年(404)

分类:

2010-03-10 12:18:42

[] [] [] []

书上的一个例子:
cat sed31.txt
.Ah "Comment"
.Ah "Substitution"
.Ah "Delete"
.Ah "Append, Insert and Change"
.Ah "List"
this line is out!
如果我用脚本直接运行:
sed '/^\.Ah/{
> p
> s/"//g
> s/^\.Ah //p
> }' sed31.txt
.Ah "Comment"
Comment
Comment
.Ah "Substitution"
Substitution
Substitution
.Ah "Delete"
Delete
Delete
.Ah "Append, Insert and Change"
Append, Insert and Change
Append, Insert and Change
.Ah "List"
List
List
this line is out!
如果我用脚本文件运行:
cat sed3.sh
/^\.Ah/{
p
s/"//g
s/^\.Ah //p
}

sed -f sed3.sh sed31.txt
.Ah "Comment"
Comment
.Ah "Substitution"
Substitution
.Ah "Delete"
Delete
.Ah "Append, Insert and Change"
Append, Insert and Change
.Ah "List"
List

为什么会有这个差异?
请高人指点!


| | |

回复 alfred1980


    在同一个环境下运行的?
alias 输出什么?
__________________________________

LIVE FREE OR DIE!     K.I.S.S.  DRY



| | |

同一个环境下
alias后的结果是:
autoload='typeset -fu'
chmod=/usr/bin/chmod
command='command '
functions='typeset -f'
hash='alias -t -'
history='fc -l'
integer='typeset -i'
la='ls -a'
ll='ls -l'
local=typeset
ls=/usr/bin/ls
nohup='nohup '
r='fc -e -'
sed=/usr/bin/sed
stop='kill -STOP'
suspend='if [[ ${0#-} = $0 ]] ; then kill -STOP $$; else dspmsg -s 1 ksh.cat SUSPEND "suspend: cannot suspend login shell
"; fi '
type='whence -v'
vi=/usr/bin/vi


| | |

从结果看,第二个命令使用了-n选项。

应该是你自己弄错了。
__________________________________

LIVE FREE OR DIE!     K.I.S.S.  DRY



| | |

我这里一切正常
$ sed -f sed3.sh sed31.txt
.Ah "Comment"
Comment
Comment
.Ah "Substitution"
Substitution
Substitution
.Ah "Delete"
Delete
Delete
.Ah "Append, Insert and Change"
Append, Insert and Change
Append, Insert and Change
.Ah "List"
List
List
this line is out!
__________________________________


| | |

2.png 1.png

黑哥,我没搞错了!!!


| | |

痛苦啊!


| | |

回复 alfred1980


    你贴上来的代码和你运行的代码完全一样?
__________________________________

LIVE FREE OR DIE!     K.I.S.S.  DRY



| | |

检查你的脚本文件第一行是不是"#n"这样的注释行。
__________________________________

LIVE FREE OR DIE!     K.I.S.S.  DRY



| | |

痛苦都是自找的,别人无法让你痛苦。
__________________________________

LIVE FREE OR DIE!     K.I.S.S.  DRY



| | |
  » » »
  快速回复主题
[] [] [] []

对!
难道是#n造成的?

果然是,为什么啊?


| | |
阅读(568) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~