Hi Kishore, The below snippet will get your desired result.
------------------------------------------------------------------------------------------------------------------------------- #!/usr/bin/perl use strict ; my @structure_name = (); my $fni = 'd:\Sample.txt' ; my $fno = 'd:\ashok.txt' ; my $flag = 0; open my $fhi, '<', $fni or die "open '$fni' failed: $!" ; open my $fho, '>', $fno or die "open '$fno' failed: $!" ; while (<$fhi>) { if ($flag == 1 && $_ !~ /\}/) { push @structure_name, $_ if (grep {/NEED*/i} $_); next; } else { $flag = 0; } if($_ =~ /knk.+pmk.*/g || $_ =~ /pmk.+knk.*/g) { push @structure_name, $_; $flag = 1; } } map {$_ =~ s/(\s| )+//g} @structure_name; foreach my $need (@structure_name) { my ($key, $value) = split(/=/, $need); if ($value eq '{') { $key =~ s/some//; print $fho "Structure : $key\n"; } elsif($key =~ /NEED/) { print $fho "$key : $value\n"; } } close $fho; close $fhi ; ------------------------------------------------------------------------------------------------------------------------------- Let me know if you find it difficult to understand. Hope script is not that complicated to understand :). Have a nice time, Njoyyyyyyyy. Rudd - Please do let me know how good i can optimize above script. :o) Ashok On 9/4/06, Nagakishor, K <[EMAIL PROTECTED]> wrote:
I have a file containing 100's of structures in it. In that file I need to identify the structures with particular name (ex: N1 AND N2) and dump the values of only some fields (ex: P1 AND P2) in to another file. If a structure does not contain the names N1 AND N2, then we should skip it. May anyone have a code for this or any idea of how to do this?