Chinaunix

标题: file format exchange question [打印本页]

作者: Pacific Yan    时间: 2003-07-22 01:20
标题: file format exchange question
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,
作者: 夜未眠    时间: 2003-07-22 01:32
标题: file format exchange question

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

对了,上面两行最前面的$和>是提示符
作者: bjgirl    时间: 2003-07-22 01:40
标题: file format exchange question
$cat file1|tr "," "\n" >file2
作者: Pacific Yan    时间: 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);
作者: admirer    时间: 2003-07-22 07:56
标题: file format exchange question
awk -F"," '{for(i=1;i<=NF;printf"%s\n",$i++)}'  file
作者: anonimousboy    时间: 2003-07-22 08:05
标题: file format exchange question
[quote]原帖由 "admirer"]awk -F"," '{for(i=1;i<=NF;printf"%s\n",$i++)}'  file[/quote 发表:
     
我发现我们两个有时候想法总是一样~~嘿嘿~~心灵感应~~
作者: Pacific Yan    时间: 2003-07-22 21:17
标题: file format exchange question
Thanks a lot,
作者: powerplane    时间: 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
复制代码

作者: Pacific Yan    时间: 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,




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2