Hope this helps you.

use strict;
use warnings;
open my $fh, '<', "infile.txt" or die $!;
open my $ofh, '>', "outfile.txt" or die $!;
local $/ = "};";
my %printed;
my @a  = <$fh>;
my @b = ();
foreach(@a){
    if ($_ =~ m/(.*?)\_T\n/){        
        my $tomatch = $1;
        my $cnt =  grep /$tomatch/,@b;        
        if($cnt == 0){
            push(@b,$_);
        }
        #print $tomatch."\n";
    }
}
print $ofh @b;

Thanks and Regards,
Prabu.M.A

Dharshana Eswaran <[EMAIL PROTECTED]> wrote: Hi All,

I am reading a certain data from one file and writing to another file. In
the original file, there are few lines, which occur more than once in
different lines. When i am writing it to the second file, i don't want it to
be written more than once. I mean, it should not be repetitive. The file are
just two simple text files.

In achieving what i need, i thought simultaneous reading and writing to the
file is required, to know if the lines are being written for the second
time. But i don't know how to achieve this.

A sample of the text file is shown below:
STACK_CC_SS_COMMON_TYPE_REFERENCE_ID_T
{
    STACK_CC_SS_COMMON_TYPE_REFERENCE_PROTOCOL_DIS_T
protocol_discriminator;
    STACK_CC_SS_COMMON_TYPE_REFERENCE_TRANSACTION_ID_T   transaction_id;
} STACK_CC_SS_COMMON_TYPE_REFERENCE_ID_T;
};
STACK_CC_SS_COMMON_TYPE_CHANNEL_INFO_T
{
    STACK_CC_SS_COMMON_TYPE_CHANNEL_TYPE_T channel_type;
    STACK_CC_SS_COMMON_TYPE_CHANNEL_MODE_T channel_mode;
} STACK_CC_SS_COMMON_TYPE_CHANNEL_INFO_T;
};
STACK_CC_SS_COMMON_TYPE_REFERENCE_ID_T
{
    STACK_CC_SS_COMMON_TYPE_REFERENCE_PROTOCOL_DIS_T
protocol_discriminator;
    STACK_CC_SS_COMMON_TYPE_REFERENCE_TRANSACTION_ID_T   transaction_id;
} STACK_CC_SS_COMMON_TYPE_REFERENCE_ID_T;
};

Can anyone guide me in this?

Thanks and Regards,
Dharshana


       
---------------------------------
Get the free Yahoo! toolbar and rest assured with the added security of spyware 
protection. 

Reply via email to