- 论坛徽章:
- 0
|
本帖最后由 shangat 于 2010-09-24 10:32 编辑
回复 1# bioinfor - use strict;
- use warnings;
- my ( @arr, $key, $values, $temp );
- my %hash;
- open A,"Book.txt" or die;
- while ( <A> ) {
- chomp;
- @arr = split;
- if ( @arr % 2 ) {
- $hash{$_} = "###";
- }
- else {
- $values = $arr[-1];
- s/(\w.*)\s+$values/$1/;
- $hash{$_} = $values;
- }
- }
- foreach $key ( keys %hash ) {
- @arr = split /\s+/,$key;
- if ( @arr == 3 ) {
- foreach $temp ( @arr[0,2] ) {
- if ( ( $values ) = grep $temp eq $_, values %hash ) {
- printf ("%-25s\t%-15s\n",$key, $values);
- }
- }
- }
- else {
- if ( ( $values ) = grep $arr[0] eq $_, values %hash ) {
- printf ("%-25s\t%-15s\n", $key, $values);
- }
- }
- }
复制代码 Q1:5楼 发表于 2010-09-20 21:02 | 只看该作者
如图,你的数据从第991行开始就只有1列了
Q2:还要先对 Book3.txt 处理一下,含有 ^M- sed -n 's/\r//p' Book.txt >book.txt
复制代码 或者 |
|