荔园在线

荔园之美,在春之萌芽,在夏之绽放,在秋之收获,在冬之沉淀

[回到开始] [上一篇][下一篇]


发信人: Init.bbs@bbs.zju.edu.cn (RCSC), 信区: Linux
标  题: Re: 向大家请教一个替换问题!·!·
发信站: 浙江大学海纳百川 (Mon Oct 27 19:46:34 2003)
转信站: SZU!news.ccie.net.cn!ZJUBBS

累死我了,弄好了。
这个在文件名有空格的情况下面也可以用。
[dhh@hhding test]$ more tr.sh
#!/bin/sh
# Get an unique tmp
tmp=fn`date +%N`
find ./ | while read src
do
if [ -d "${src}" ]
then
        echo "Alert! Dir $src found, no operate on it"
else
        echo "tr the file $src now ..."
        sed 's/quit/quit\
this is a book/g' "$src" > "$src.$tmp"
mv -f "$src.$tmp" "$src"
fi
done
echo "All finished, enjoy it!"

[dhh@hhding test]$

【 在 atteck@bbs.pku.edu.cn (鹰钩鼻子蛤蟆嘴,魔族战士!) 的大作中提到: 】
: 不知道为什么,现在执行
: perl -e 'while(<*>){next if -d;open FH,">>$_" or next;print FH "this is
: book"}'
: 这个命令只是在最后一行追加的
: 并不是换行再追加的
: 【 在 hace.bbs@hace.dhs.org (半边海) 的大作中提到: 】
: : 不好意思, 想起了,是打漏了, :P
: :      perl -pi -e 's/quit\n/quit\nthis is book\n/g' *.c
: :      perl -pi -e 's/quit\n/quit\nthis is book\n/g' `find . -name "*.c"`
: >>  .................<以下省略>............


--
※ 来源:·浙江大学海纳百川站 bbs.zju.edu.cn·[FROM: Init]


[回到开始] [上一篇][下一篇]

荔园在线首页 友情链接:深圳大学 深大招生 荔园晨风BBS S-Term软件 网络书店