Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Simultaneous one by one splitting and processing of an uneven file based on a pattern

by zing (Beadle)
on Sep 10, 2012 at 21:30 UTC ( #992856=perlquestion: print w/ replies, xml ) Need Help??
zing has asked for the wisdom of the Perl Monks concerning the following question:

Hi all. I have this file
Processing 12312 2343434 34344 Processing 12123 34343 Processing 12443 3434 3434 23434 Processing 1213 33434 Processing 96668 343 Processing 667 343 3437 Processing 67 63 47 7 Processing 6 667 23434 343 3434 Processing 88668
What I want is to go through this list in a selection of three.

1. After the first occurrence pattern "Processing" i have 3 lines.Save these three 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 4 lines.Save these 4 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 tyhe calculation to RESULT.txt and so on

Comment on Simultaneous one by one splitting and processing of an uneven file based on a pattern
Download Code
Re: Simultaneous one by one splitting and processing of an uneven file based on a pattern
by Anonymous Monk on Sep 10, 2012 at 21:41 UTC
    And your question is?
Re: Simultaneous one by one splitting and processing of an uneven file based on a pattern
by GrandFather (Cardinal) on Sep 10, 2012 at 21:42 UTC

    So code it up and then ask us for help if you can't get it to work.

    Don't use variables a, b and c. You tell us the first variable contains a size or count so the name should include size or count or it should be a word that describes how the count is used. From your description it should be $offset, but maybe you have the maths wrong. Variable names are important, even in pseudo code.

    True laziness is hard work
      Yes 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" }' file.txt

        And that relates to the pseudo code you gave how? Show some effort. Take the time to write good code. Avoiding typing a few characters (for names) does not save time. Asking someone to write the code for you also does not save time. If you understand the problem well enough to describe it, you understand it well enough to code it. If you don't understand the problem how are you going to describe it well enough to someone else to have it implemented? Now, pull your finger out and get busy.

        True laziness is hard work

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://992856]
Approved by GrandFather
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (5)
As of 2014-09-15 10:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite cookbook is:










    Results (146 votes), past polls