免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1231 | 回复: 8
打印 上一主题 下一主题

file format exchange question [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2003-07-22 01:20 |只看该作者 |倒序浏览
Hello, could somebody help me to write a shell script (no PERL or Java) to change the the file format from file 1 to
file 2?

file 1:

CASP1, CASP2, CASP3, CASP4, CASP5, CASP6, CASP7, CASP8, CASP9, CASP10, CASP13, .......



file 2:


CASP1
CASP2
CASP3
CASP4
CASP5
CASP6
CASP7
CASP8
CASP9
CASP10
CASP13
......



Thanks,

论坛徽章:
0
2 [报告]
发表于 2003-07-22 01:32 |只看该作者

file format exchange question


  1. $ sed 's/, /\
  2. > /g' file1
复制代码
   

对了,上面两行最前面的$和>是提示符

论坛徽章:
0
3 [报告]
发表于 2003-07-22 01:40 |只看该作者

file format exchange question

$cat file1|tr "," "\n" >file2

论坛徽章:
0
4 [报告]
发表于 2003-07-22 02:31 |只看该作者

file format exchange question

Thank you all!

Now I will see how neat the shell scripts are comparing to my following PERL script.


my perl script:
#!/usr/bin/perl -w
$file="your path for file 1";
open(FILE, $file) or die "err: $!\n";
while(<FILE> {
chomp;
my @line=split /, /, $_;
for ($i=0; $i<$#line; $i++)
{
print "$line[$i]\n";
}
}
close (FILE);

论坛徽章:
1
荣誉版主
日期:2011-11-23 16:44:17
5 [报告]
发表于 2003-07-22 07:56 |只看该作者

file format exchange question

awk -F"," '{for(i=1;i<=NF;printf"%s\n",$i++)}'  file

论坛徽章:
0
6 [报告]
发表于 2003-07-22 08:05 |只看该作者

file format exchange question

[quote]原帖由 "admirer"]awk -F"," '{for(i=1;i<=NF;printf"%s\n",$i++)}'  file[/quote 发表:
     
我发现我们两个有时候想法总是一样~~嘿嘿~~心灵感应~~

论坛徽章:
0
7 [报告]
发表于 2003-07-22 21:17 |只看该作者

file format exchange question

Thanks a lot,

论坛徽章:
0
8 [报告]
发表于 2003-07-22 21:48 |只看该作者

file format exchange question

原帖由 "acific Yan" 发表:

Now I will see how neat the shell scripts are comparing to my following PERL script....

Now I will give you a very neat perl script can be excuted by entering a command:


  1. perl -e 'while (<>){ s/,/\n/g; print $_;}' OLD_FILE > NEW_FILE
复制代码

论坛徽章:
0
9 [报告]
发表于 2003-07-22 23:52 |只看该作者

file format exchange question

haha, you are the man!  good, definitely there are a lot of things  for me to learn!

Thanks,
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP