Hello all,
I have tab delim file as follows
#file1
#version1.1
#columns with the information as follows
state1 class1 report_version_1.1 9428 4567 . . call=1;times=5;toss=head->tail;sno=A1B1;effect=positive
state1 class1 report_version_1.1 3862 4877 . . call=1;times=5;toss=head->tail;sno=A1B2;effect=negative
state1 class1 report_version_1.1 2376 4567 . . call=1;times=5;toss=head->tail;sno=;effect=positive
state2 class1 report_version_1.1 4378 2345 . . call=1;times=5;toss=tail->tail;sno=A1B3;effect=positive,negative, both
state2 class1 report_version_1.1 1289 4835 . . call=1;times=5;toss=head->tail;sno=;effect=positive
Note: There are no column headers in the file just the three top comments.
I am trying to parse out the 8 column which is basically a string separated by semi colons. I need to remove all the entries that have part1: no sno (value/name) (for eg: for 3 row sno=; i.e there is no record) and also part2: those that have same toss results i.e toss=tail->tail is not needed since both are tail. ** and finally a txt file which will have the filtered entries.
I am trying to divide it in parts and hence Here is what I have come up with so far for the **part1: sno…
#!usr/bin/perl
use warnings;
#inputfile
my $input_file = "/Users/Documents/myfolder/file1.txt";
die "Cannot open $input_file \n" unless (open(IN, $input_file));
#Open output file and write the results
die "result1.txt" unless(open( OUT,"> result1.txt"));
#In the while loop, put the columns that have to be printed in the new file.
while (<IN>) {
my ($a, $b, $c , $d, $e, $f, $g, $h, $i) = (split /\s+/)[ 1, 2, 3, 4, 5, 6, 7, 8, 9];
#if sno has no name or value then filter the file
if ( $i =~ /^[sno]/ =~ /^[sno]/ )
{
print $OUT " $a \ $b\ $c \ $d \ $e \ $f \ $g \ $h \ $i \n";
}
}
exit;
Any other better ways to solve this for both sno and toss parts together?