Perl pattern extraction from file -
i have text file :
name : first file name : first_1 year : 12 etc etc etc t1 : t1 t2 : t2 t3 : t3 conclusion : success name : first file name : first_2 year : 13 etc etc etc t1 : t1 t2 : t2 t3 : t3 conclusion : success name : second file name : second_1 year : 12 etc etc etc t1 : t1 t2 : t2 t3 : t3 conclusion : failure name : first file name : first_3 year : 12 etc etc etc t1 : t1 t2 : t2 t3 : t3 conclusion : success
and on.....
i need perl script gives me following output:
naming file_name year conclusion reason first first_1 12 success t1, t2, t3 first first_2 13 success t1, t2, t3 second second_1 12 failure t1, t2, t3 first first_3 12 success t1, t2, t3
the following need. reads file parse stdin. other array of lines.
#!/usr/bin/perl use strict; $naming = ""; $file_name = ""; $year = ""; @reason = (); $conclusion = ""; print "naming\tfile_name\tyear\tconclusion\treason\n"; while (my $line = <stdin>) { $line =~ /conclusion : (\w+)/ , { $conclusion = $1; print "$naming\t$file_name\t$year\t$conclusion\t" . join(", ",@reason) . "\n"; $naming = ""; $file_name = ""; $year = ""; @reason = (); $conclusion = ""; }; $line =~ /name : (.*)/ , $naming = $1; $line =~ /file name : (.*)/ , $file_name = $1; $line =~ /year : (\d+)/ , $year = $1; $line =~ /t\d : (.*)/ , push(@reason,$1); }
Comments
Post a Comment