Need to search a particular String form a file a write to another file using perl script

I have file which contains a huge amount of data. I need to search the pattern Message id. When that pattern is matched I need to get abcdeff0-1g6g-91g3-1z2z-2mm605m90000 to another file.
Kindly provide your input.

File is like below

Jan 11 04:05:10 linux100 |NOTICE |NET|NETDPCclient|thread:1|pid:[1234]: Message id, step 4 (abcdeff0-1g6g-91g3-1z2z-2mm605m90000)

Itried like this but its not working.

$Log="msg.log";
$OVOMSGIDFILE ="file.log";
 
open(LIST1, "<$Log") or die "Could not open chr1_22.txt: $!";
open(OUTPUT, "+>FILE") or die "Could not open chr1_23.txt: $!" ;
foreach my $line1 (<LIST1>)
{
chomp($line1);
# $line =~ m/'$1 if /Message id.+?(\w+-\w+-\w+-\w+-\w+)/'/);
'say $1 if /Message id.+?\((.+?)\)/' > OUTPUT;
#!/usr/bin/perl
#

use strict;

# define files
my $infile = "chr1_22.txt";
my $outfile = "chr1_23.txt";

# open infile in read mode and outfile in write mode
open(INFILE, "<$infile") or die "Unable to open: $infile.\n";
open(OUTFILE, ">$outfile") or die "Unable to write to: $outfile.\n";

# loop through infile and write captured regex pattern
# to outfile
while(<INFILE>) {
    print OUTFILE "$1\n" if(/.*Message\sid.*\((.*)\)/);
}

# close both files
close(INFILE);
close(OUTFILE);

# done
exit(0);

cat chr1_23.txt
abcdeff0-1g6g-91g3-1z2z-2mm605m90000
1 Like

Thank you :slight_smile: