
nitinp
Novice
Oct 11, 2006, 3:32 AM
Post #5 of 12
(3652 views)
|
|
Re: [davorg] need help on this
[In reply to]
|
Can't Post
|
|
Hi, I have posted the code.When I supply the input in input.txt it is of this form. Line 10 88 88 77 77 66 66 22 22 88 88 77 77 66 66 22 22 66 66 22 22 Line 11 99 99 99 99 88 88 88 88 88 88 88 88 88 88 88 88 66 66 22 22 44 (last line) Line 100 99 Instead of this. Line 1 sdksjdksjd Line 2 kdsdksjd Line 10 88 88 77 77 66 66 22 22 88 88 77 77 66 66 22 22 66 66 22 22 Line 100 99 Line 101 sasasjaksjasajs I dont know how many lines would be present before line 10 so assume that only when we search for this pattern we can get to know where to start reading the actual input from.I also dont know how many lines can exist after line 100.We have to stop there based on the same pattern.Each of these patterns are seperated based on 3 spaces that I use as a split mechanism. I also assume that there are 5 such patterns on each line which could also vary based on para.We need to generalize this too. Each of these lines after line 10 and line 11 and so will have the same count of patterns. Line 1 and line 2 both have 5 sets of this pattern 88 88 77 77.So we should have this number as 5. Here is my code. My output should have these patterns stored line after line seperated by one space. # open output file,if it already exists then delete it if( -e $outputfile) { unlink($outputfile); } # open output file in append mode. open (MYFILE, '>>output.txt'); @data = <IN>; # counting no of lines in a file. seek (IN,0,0); while ($line = <IN>) { $n++; } for($no_of_lines=0;$no_of_lines<$n;$no_of_lines++) { my @values= split(' ', $data[$no_of_lines]); # I assume that there are 5 columns for the inner for loop there could be 6 too # we need to actually figure how many such columns exist based on the pattern. for($i=1;$i<5;$i++) { $newvalues[$i]=$values[$i]; } print MYFILE @newvalues; #adds a space after every pattern is printed. print MYFILE " "; } close (MYFILE); close IN; The new code should actually ignore what comes before line 10 and what comes after line 100. Its not always line 10 where pattern starts and not always line 100 where pattern ends. Pattern always ends with a two chartacters. The patterns are numbers from 0-9 and a to f so we can say hex. So we could also have a pattern like this aa 77 88 22 and could end with bb Thanks. Regards. Nit
|