请教数据换行!!!

请教数据换行!!!

请教数据换行!!!
name org link3map name4
path:ath00140 ec:1.3.1.3 enzyme
path:ath00140 ec:1.14.15.4 enzyme
path:ath00020 ath:AT1G23800 ath:AT3G48000 gene
path:ath00020 ath:AT4G33070 ath:AT5G01320 ath:AT5G01330 gene



将上面的1.txt变为

name org link3 map name4
path:ath00140 ec:1.3.1.3 enzyme
path:ath00140 ec:1.14.15.4 enzyme
path:ath00020 ath:AT1G23800 gene
ath:AT3G48000 gene
path:ath00020 ath:AT4G33070 gene
ath:AT5G01320 gene
ath:AT5G01330 gene

程序应该怎么写呢 link3 map列遇到ath分行,name4列要将此属性复制到下一行,其他列为空




   

name org .
name org link3map name4
path:ath00140 ec:1.3.1.3 enzyme
ec:1.14.15.4 enzyme
path:ath00020 ath:AT1G23800 gene
ath:AT3G48000 gene
ath:AT4G33070 gene
ath:AT5G01320 gene
ath:AT5G01330 gene

可以直接写成上面这样的吧?
对啊!name org 为一列,li.
对啊!name org 为一列,link3 map 为一列,name4为一列,三列的数据其实很多,手动就很费劲了
假设列于列之间是用"\t”分开,ath:AT4G33070 ath:AT5G01320 ath:AT5G01330之间是一个空格,程序如下:
open IN,"file.txt" ||die "$!";
open OUT,">out.txt" ||die "$!";

while (<IN>)
{
@array = split "\t",$_;
chomp $array[2];
if ($array[1] =~ /ath/ig)
{
@tmp = split " ",$array[1];
print OUT "$array[0]\t$tmp[0]\t$array[2]\n";
shift @tmp;
foreach $ath(@tmp)
{
print OUT "\t\t$ath\t$array[2]\n";
}
}
else
{
print OUT $_;
}
}
如果不是这样,稍微修改下就行了。
my @lines = `type in.
my @lines = `type input.txt`; # use `cat` on Unix
print @lines, '-' x 80, "\n";
for (my $i = 0; $i <= $#lines; ++$i) {
while ($lines[$i] =~ s/(^.*?\s+)(ath.*\s+)(ath.*?\s+)(.*$)/"$1$2" . ' ' x length($3) . "$4"/e) {
splice(@lines, $i + 1, 0, ' ' x length($1) . $3 . ' ' x length($2) . "$4\n");
}
}
print @lines;


PS: 输出结果均按原格式对齐, 和你的例子是一致的.




   

感谢4楼的,输出 的效果很好!!!!
lkowxtpvd
EUzfgi <a href="http://qkrzgjgootjz.com/">qkrzgjgootjz</a>, [url=http://lbcwabafkboo.com/]lbcwabafkboo[/url], [link=http://jskrxmclghkt.com/]jskrxmclghkt[/link], http://iuwvsmshdfpo.com/

[img]http://rhjpqnfdmffg.com/[/img]
[COLOR=BLUE]URL:[/COLOR][url]tvqfldcIA[/url]