Shell programming problem (Borne Shell or Korn Shell)
登录 | 论坛导航 -> 华新鲜事 -> 技术の宅 | 本帖共有 19 楼,分 1 页, 当前显示第 1 页 : 本帖树形列表 : 刷新 : 返回上一页
<<始页  [1]  末页>>
作者:香陵居士 (等级:16 - 好恐怖呀,发帖:22662) 发表:2005-01-05 19:00:04  楼主  关注此帖
Shell programming problem (Borne Shell or Korn Shell)
How to change all files in a directory from one extension to another one? Thanks!
最新推出专栏《倾听索罗斯》 欢迎大家前来捧场!

Yeah!
欢迎来到华新中文网,踊跃发帖是支持我们的最好方法!原文 / 传统版 / WAP版只看此人从这里展开收起列表
作者:吴永铮 (等级:8 - 融会贯通,发帖:2078) 发表:2005-01-05 20:29:56  2楼 评分:
man rename
rename .foo .bar *.foo
欢迎来到华新中文网,踊跃发帖是支持我们的最好方法!原文 / 传统版 / WAP版只看此人从这里展开收起列表
作者:香陵居士 (等级:16 - 好恐怖呀,发帖:22662) 发表:2005-01-06 10:36:42  3楼
man renamerename .foo .bar *.foo
Can not find such command
sngclrt01 mengdi 167: man rename
No manual entry for rename.
sngclrt01 mengdi 168: man -k rename
sngclrt01 mengdi 169: rename
ksh: rename: not found
sngclrt01 mengdi 170: sh
sngclrt01 mengdi 171: rename
sh: rename: not found
欢迎来到华新中文网,踊跃发帖是支持我们的最好方法!原文 / 传统版 / WAP版只看此人从这里展开收起列表
作者:逃课专家 (等级:11 - 出神入化,发帖:3796) 发表:2005-01-06 11:13:18  4楼
mv *.abc *.xyz
欢迎来到华新中文网,踊跃发帖是支持我们的最好方法!原文 / 传统版 / WAP版只看此人从这里展开收起列表
作者:香陵居士 (等级:16 - 好恐怖呀,发帖:22662) 发表:2005-01-06 12:08:46  5楼
please do not guess...
sngclrt01 mengdi 180: ls *.a
a.a b.a c.a
sngclrt01 mengdi 181: mv *.a *.b
mv: *.b not found
欢迎来到华新中文网,踊跃发帖是支持我们的最好方法!原文 / 传统版 / WAP版只看此人从这里展开收起列表
作者:逃课专家 (等级:11 - 出神入化,发帖:3796) 发表:2005-01-06 14:14:15  6楼 评分:
please do not guess...sngclrt01 mengdi 180: ls *.a a.a b.a c.a sngclrt01 mengdi 181: mv *.a *.b mv: *.b not found
for f in *.abc
base=(忘了).xyz
mv $f $base
done
欢迎来到华新中文网,踊跃发帖是支持我们的最好方法!原文 / 传统版 / WAP版只看此人从这里展开收起列表
作者:吴永铮 (等级:8 - 融会贯通,发帖:2078) 发表:2005-01-06 15:15:34  7楼
Can not find such commandsngclrt01 mengdi 167: man rename No manual entry for rename. sngclrt01 mengdi 168: man -k rename sngclrt01 mengdi 169: rename ksh: rename: not found sngclrt01 mengdi 170: sh sngclrt01 mengdi 171: rename sh: rename: not found
可能是linux专有的吧
# rpm -qf `which rename`
util-linux-2.12a-16

# man rename
RENAME(1) Linux Programmer's Manual RENAME(1)

NAME
rename - Rename files

SYNOPSIS
rename from to file...

DESCRIPTION
rename will rename the specified files by replacing the first occur-
rence of from in their name by to.

For example, given the files foo1, ..., foo9, foo10, ..., foo278, the
commands

rename foo foo0 foo?
rename foo foo0 foo??

will turn them into foo001, ..., foo009, foo010, ..., foo278.

And
rename .htm .html *.htm
will fix the extension of your html files.

SEE ALSO
mv(1)

1 January 2000 RENAME(1)
欢迎来到华新中文网,踊跃发帖是支持我们的最好方法!原文 / 传统版 / WAP版只看此人从这里展开收起列表
作者:香陵居士 (等级:16 - 好恐怖呀,发帖:22662) 发表:2005-01-06 18:18:15  8楼
for f in *.abcbase=(忘了).xyz mv $f $base done
...
欢迎来到华新中文网,踊跃发帖是支持我们的最好方法!原文 / 传统版 / WAP版只看此人从这里展开收起列表
作者:MrDJay (等级:10 - 炉火纯青,发帖:10172) 发表:2005-01-06 20:41:58  9楼 评分:
not the most efficient one, since i am new to perl. but enough for your work
#!/usr/bin/perl
@list = `ls test/*.b`;
foreach $a (@list){
chomp($a);
$com = "mv ".$a." $a.c";
exec($com);
}


assume your dir is "test" your old extension is .b , new one is .c

I hope to see perl experts to show me the greatest power of perl by doing same job using many and much more efficient ways :)

欢迎来到华新中文网,踊跃发帖是支持我们的最好方法!原文 / 传统版 / WAP版只看此人从这里展开收起列表
作者:JiuJie (等级:2 - 初出茅庐,发帖:17) 发表:2005-01-06 21:43:50  10楼 评分:
看看这个可以么?没在公司,不能测试
for example from *.abc to *.cde

source=`ls *.abc`
for file in $source
do
newfile=`echo $file | sed s'/.abc/.cde/g'`
#先不要用mv, 用echo看看$newfile名字对不,
#免得给你文件弄坏了
mv $file $newfile
done

欢迎来到华新中文网,踊跃发帖是支持我们的最好方法!原文 / 传统版 / WAP版只看此人从这里展开收起列表
作者:JiuJie (等级:2 - 初出茅庐,发帖:17) 发表:2005-01-06 21:47:04  11楼
man renamerename .foo .bar *.foo
rename是函数吧,她要的应该是shell
欢迎来到华新中文网,踊跃发帖是支持我们的最好方法!原文 / 传统版 / WAP版只看此人从这里展开收起列表
作者:SmellsLikeTeenSpirit (等级:11 - 出神入化,发帖:6371) 发表:2005-01-07 01:07:13  12楼
可能是linux专有的吧# rpm -qf `which rename` util-linux-2.12a-16 # man rename RENAME(1) Linux Programmer's Manual RENAME(1) NAME rename - Rename files SYNOPSIS rename from to file... DESCRIPTION rename will rename the specified files by replacing the first occur- rence of from in their name by to. For example, given the files foo1, ..., foo9, foo10, ..., foo278, the commands rename foo foo0 foo? rename foo foo0 foo?? will turn them into foo001, ..., foo009, foo010, ..., foo278. And rename .htm .html *.htm will fix the extension of your html files. SEE ALSO mv(1) 1 January 2000 RENAME(1)
应该是的
欢迎来到华新中文网,踊跃发帖是支持我们的最好方法!原文 / 传统版 / WAP版只看此人从这里展开收起列表
作者:香陵居士 (等级:16 - 好恐怖呀,发帖:22662) 发表:2005-01-07 09:33:16  13楼
not the most efficient one, since i am new to perl. but enough for your work#!/usr/bin/perl @list = `ls test/*.b`; foreach $a (@list){ chomp($a); $com = "mv ".$a." $a.c"; exec($com); } assume your dir is "test" your old extension is .b , new one is .c I hope to see perl experts to show me the greatest power of perl by doing same job using many and much more efficient ways :)
I mean shell script... :P
Perl is not installed yet.
欢迎来到华新中文网,踊跃发帖是支持我们的最好方法!原文 / 传统版 / WAP版只看此人从这里展开收起列表
作者:MrDJay (等级:10 - 炉火纯青,发帖:10172) 发表:2005-01-07 10:15:05  14楼
I mean shell script... :PPerl is not installed yet.
.........u...
欢迎来到华新中文网,踊跃发帖是支持我们的最好方法!原文 / 传统版 / WAP版只看此人从这里展开收起列表
作者:JiuJie (等级:2 - 初出茅庐,发帖:17) 发表:2005-01-07 10:16:04  15楼
看看这个可以么?没在公司,不能测试for example from *.abc to *.cde source=`ls *.abc` for file in $source do newfile=`echo $file | sed s'/.abc/.cde/g'` #先不要用mv, 用echo看看$newfile名字对不, #免得给你文件弄坏了 mv $file $newfile done
tested in Solaris 2.5 successfully.
Before test:
~/tmp/test/[116]> ls
~/tmp/test/[116]> 1 2 1.abc 2.abc 3.dd

After test:
~/tmp/test/[116]> ls
~/tmp/test/[116]> 1 2 1.cde 2.cde 3.dd


Please try.
欢迎来到华新中文网,踊跃发帖是支持我们的最好方法!原文 / 传统版 / WAP版只看此人从这里展开收起列表
作者:JiuJie (等级:2 - 初出茅庐,发帖:17) 发表:2005-01-07 10:18:31  16楼
记得你好象曾经提起过有一个命令可以查当前是什么系统
比如telnet进去,想知道是什么操作系统,什么机型.怎么实现呢?
欢迎来到华新中文网,踊跃发帖是支持我们的最好方法!原文 / 传统版 / WAP版只看此人从这里展开收起列表
作者:吴永铮 (等级:8 - 融会贯通,发帖:2078) 发表:2005-01-07 12:12:34  17楼
记得你好象曾经提起过有一个命令可以查当前是什么系统比如telnet进去,想知道是什么操作系统,什么机型.怎么实现呢?
uname -a?
欢迎来到华新中文网,踊跃发帖是支持我们的最好方法!原文 / 传统版 / WAP版只看此人从这里展开收起列表
作者:吴永铮 (等级:8 - 融会贯通,发帖:2078) 发表:2005-01-07 12:13:54  18楼
rename是函数吧,她要的应该是shell
看清楚,是RENAME(1),不是RENAME(2)。
欢迎来到华新中文网,踊跃发帖是支持我们的最好方法!原文 / 传统版 / WAP版只看此人从这里展开收起列表
作者:JiuJie (等级:2 - 初出茅庐,发帖:17) 发表:2005-01-07 23:53:02  19楼
谢谢
欢迎来到华新中文网,踊跃发帖是支持我们的最好方法!原文 / 传统版 / WAP版只看此人从这里展开收起列表
论坛导航 -> 华新鲜事 -> 技术の宅 | 返回上一页 | 本主题共有 19 篇文章,分 1 页, 当前显示第 1 页 | 回到顶部
<<始页  [1]  末页>>

请登录后回复:帐号   密码