Hello All, Yesterday I posted a question asking if anyone can suggest a way of accomplishing this. In the mean while I have comeup with a quick and dirty way of processing the data file and sorting it in an array. Once it is sorted, then, I can do whatever however I need to. Code is attached below. If you have any suggestions on better way of accomplishing the same task, please share.
Thanks ---------------------------------------------------------------------- #!/usr/bin/perl $want=1; $count=0; open(STDIN, "test.txt"); @array=<STDIN>; close (STDIN); print "Size of the Array is $#array\n"; print "@array\n"; for ($x=0; $x <= $#array; $x++) { print "Index[$x] ----> $array[$x]\n"; } #################################################### $k=0; foreach $line (@array){ chomp $line; if ($line =~ /Product/g) { if (++$count == $want) { print "line number is ---> $k\n"; $FIRST=$k; } } $k++; } $i=0; $want=1; $count=0; foreach $line (@array){ chomp $line; if ($line =~ /System Totals/g) { if (++$count == $want) { print "line number is ---> $i\n"; $LAST=$i; } } $i++; } $j=0; for ($ii=$FIRST; $ii <= $LAST; $ii++) { $array2[$j] = $array[$ii]; $j++; } for ($y=0; $y <= $#array2; $y++) { print "Index[$y] ----> $array2[$y]\n"; } print "FIRST--> $FIRST and LAST--->$LAST\n"; ------------------------------------------------------------------------- -----Original Message----- From: Naser Ali [mailto:[EMAIL PROTECTED] Sent: Tuesday, June 15, 2004 4:22 PM To: [EMAIL PROTECTED] Subject: how to sort certain pattern from a file Below is a sample report. I have been able to only capture lines between "Intance Name" and "System totals", but here is my delima. The menus on the report are repeated several times. For example, the line starts with "Instance Name" appears twice. I only want to capture the lines between first occurence of "Instance Name" and upto "System Totals" , process it or copy in another temp file and then delete it from the original file, so I can process the next one and so on and so forth. Also, as you can see that each "Task" has three lines underneath it with related data, how can I process it and associate it in arrays or lists.What is the best of doing it? For instance, for "Task 1", I would like to capture lines starting with "Avg/Inst", "Avg/Occ.Inst", and " Total Count" be stored in an array or a file, which ever is best to process later, but keep the association maintained. I ll truly appreciate any help and pointers. Thanks ============================================================================ =============== Instance Month Last Year Last name Today Yesterday to Date Month to Date Year -------- --------- --------- --------- --------- --------- --------- Task 1 Avg/Inst 0.03 0.00 0.00 0.04 0.03 0.03 Avg/Occ.Inst 0.03 0.00 0.00 0.04 0.03 0.03 Total Count 8.08 0.00 8.08 303.00 1842.24 2512.88 Task 2 Avg/Inst 0.03 0.00 0.00 0.04 0.03 0.03 Avg/Occ.Inst 0.03 0.00 0.00 0.04 0.03 0.03 Total Count 7.81 0.00 7.81 335.83 2147.75 2631.97 Task 3 Avg/Inst 0.00 0.03 0.03 0.01 0.02 0.03 Avg/Occ.Inst 0.00 0.03 0.03 0.01 0.02 0.03 Total Count 0.00 7.56 7.56 109.62 965.79 2509.92 Insts 250 250 250 7500 62644 93496 Occ. Insts 250 250 250 7500 62625 93496 Avg/Inst 0.15 0.18 0.33 0.38 0.35 0.36 Avg/Occ.Inst 0.15 0.18 0.33 0.38 0.35 0.36 System Totals 36.36 45.03 81.39 2877.72 21922.86 33578.77 Reports menu?r Instance Month Last Year Last name Today Yesterday to Date Month to Date Year -------- --------- --------- --------- --------- --------- --------- Task 1 Avg/Inst 0.00 0.02 0.02 0.01 0.01 0.02 Avg/Occ.Inst 0.00 0.02 0.02 0.01 0.01 0.02 Total Count 0.00 4.85 4.85 101.85 902.10 1760.55 Task 2 Avg/Inst 0.00 0.02 0.02 0.03 0.03 0.02 Avg/Occ.Inst 0.00 0.02 0.02 0.03 0.03 0.02 Total Count 0.00 6.00 6.00 228.00 2058.00 342.00 Task 3 Avg/Inst 0.03 0.00 0.00 0.04 0.03 0.03 ..................... ..................... ..................... ..................... ..................... ..................... ..................... ..................... ============================================================================ ===============