
rushadrena
Novice
Sep 10, 2012, 2:42 PM
Views: 1486
|
|
Re: [Laurent_R] A file parsing and 2D array/matrix problem.
|
|
|
Hi Laurent and Chris I didnt see that coming. I have fixed that error by introducing this Now I have this huge file matrix.txt(I have snipped the file so as to contain only 2x5 matrices for a concise view) which I have to further process : Simultaneously one by one splitting and processing
Processing 10011 01010 Processing 11110 01010 Processing 11100 00110 Processing 10010 11001 Processing 11110 00001 Processing 11010 00110 Processing 10101 01010 Processing 00111 11100 Processing 11010 11111 What I want is to go through this list in a selection of three. 1. After the first occurrence pattern "Processing" i have 2 lines.Save these 2 lines in a separate file.save the file size of this file in variable "a" 2. After 2nd occurrence of "Processing", I have 2 lines.Save these 2 lines in a separate file.save the file size of this file in variable "b" 3. After 3rd occurrence of "Processing", I have 2 lines.Save these 2 lines in a separate file.save the file size of this file in variable "c" Now I'd perform an operation $a+$b/$c >> RESULT.txt. Then select other triplet i.e. 4th,5th and 6th occurence of "Processing" save the calculation to RESULT.txt and so on. [EDIT:] I did tried these two codes, but they dont cater to the triplet selection
perl -ne 'BEGIN{ $/="Processing"; } if(/^\s*(\S+)/){ open(F,">$1.out")||warn"$1 write failed:$!\n";chomp;print F "gi", $_ }'
awk -vRS="Processing" '{ print $0 > "file"t++".out" }' matrix.txt
(This post was edited by rushadrena on Sep 10, 2012, 2:58 PM)
|