modify a format

Hi I have a format that looks like this:

#TailType       TwoSided
#Scale to target        True
#Target Intensity       100
#Intensities    PM/MM
#Treatment CEL  ./G.CEL
#Control CEL    ./F.CEL
chr1    16      0
chr1    24      0
chr1    32      0.187188
chr1    40      0.14595
chr1    48      0.569928
chr1    56      1.05253
chr1    64      0.773825
chr1    72      0
chr1    80      0.0284669

What I want to do is delete all rows with # then have it so it looks like this:

chr1    16      24     0
 chr1    24      32     0
 chr1    32      40     0.187188
 chr1    40      48     0.14595
 chr1    48      56     0.569928
 chr1    56      64     1.05253
 chr1    64      72     0.773825
 chr1    72      80     0
 chr1    80      etc.         0.0284669

The file is tab deliminted.

It would be best if this can be written in Perl but awk is fine too.

One of the sed and awk solution..

sed '/^#/d' inputfile > outfile
awk '!/^#/' inputfile > outfile

thanks but there is still one more step :wink:

Ah! i did'n notice that..

awk 'NR==FNR{a[FNR]=$2;next}!/^#/{print a[FNR+1]!=""?$1 FS $2 FS a[FNR+1] FS $3:$1 FS $2 FS "etc." FS $3}' inputfile inputfile > outfile

try,

 
awk '!/^#/{if(a!=""){print a" "b" "$2" "c}a=$1;b=$2;c=$3;}END{print a" "b" etc "c}' inputfile > outfile

A Perl adaptation of xoops solution:

#!/usr/bin/perl
   
open(DAT,shift) or die "Unable to open file \n";

foreach ( <DAT> ) {
   unless ( /^#/ ) {
      ($a,$b,$c)=split(/\s+/,$_);
      print "$A $B $b $C\n" if ( $B ne "" ) ;
      ($A,$B,$C)=($a,$b,$c);
      }
   }
print "$A $B etc. $C\n" if ( $A ne "" )  ;

close(DAT);