http://www.perlmonks.org?node_id=1082217

taj_ritesh has asked for the wisdom of the Perl Monks concerning the following question:

Let me define the problem first, I have a file of some 1 million lines, this is the output data from a tool, which reports the timing data from some predefined start & end point. Now I need to do following fine task :- 1):- Need to get the wort path report, basically there is a word "slack" in this file & we need to search for that. each slack belongs to a particular start & end point. we need to get all the lines from "startpoint" to "slack" for this worst slack number. 2):- Now as we got the worst path, once section of this is data path & other is clock path, we need to get the all the lines from startpoint to "data arrival time". 3):- now we need to make a table from first column & fifth column in this table .sort this table & find the worst delay gate in this path.

Replies are listed 'Best First'.
Re: Need a help for perl coding
by salva (Canon) on Apr 14, 2014 at 09:51 UTC
    Your problem seems solvable with a program written in Perl.

    We will be very glad to help you with any specific issue related to Perl programming you may find. Good luck!

Re: Need a help for perl coding
by DrHyde (Prior) on Apr 14, 2014 at 10:33 UTC
    Whenever I need to pull particular columns out of a file, my weapon of choice for small scripts is awk(1) if the columns are delimited, or cut(1) if they're fixed length. If things get even slightly complicated, perl with Text::CSV_XS.
Re: Need a help for perl coding
by pvaldes (Chaplain) on Apr 14, 2014 at 09:52 UTC
    I'm not understanding the problem, but read about: perl regexes and split or print $F[X] where X is the number of the desired column minus one. (i.e: print "$F[0], $F[4]"; prints the first and fifth columns)
Re: Need a help for perl coding
by NetWallah (Canon) on Apr 14, 2014 at 17:25 UTC
    Please use <p> </p> tags around your paragraphs. (and <code> </code> tags around your code). (See Writeup Formatting Tips)

    Posting minimal sample data would also encourage monks to demonstrate how to parse it.

            What is the sound of Perl? Is it not the sound of a wall that people have stopped banging their heads against?
                  -Larry Wall, 1992

Re: Need a help for perl coding
by sundialsvc4 (Abbot) on Apr 14, 2014 at 18:00 UTC

    First blush ...

    1):- Need to get the worst path report, basically there is a word "slack" in this file & we need to search for that. each slack belongs to a particular start & end point. we need to get all the lines from "startpoint" to "slack" for this worst slack number. 2):- Now as we got the worst path, once section of this is data path & other is clock path, we need to get the all the lines from startpoint to "data arrival time". 3):- now we need to make a table from first column & fifth column in this table .sort this table & find the worst delay gate in this path.

    Presumably, this is a “line by line” massive text file – who really cares how many hundreds of megabytes it is, which presumably consists of lines that begin-with or that contain (among other things) startpoint and slack.   Therefore, your first order of business will be to know how to identify those lines, and how to parse interesting bits of data from them.   Your description implies that slack_number is some kind of grouping-field but does not explain what that might be ... is the input-file, for instance, “sorted by” that field?

    Moving on ... presumably the presence of a startpoint record marks the beginning of a new group (hence, the ending of the previous one), and slack, say, denotes the presence of some “interesting-to-us” data point within the present group.   I also deduce that this data must contain data_path and clock_path.   So now, at this point, I can hazard a guess as to what marks the boundaries of a particular “set of data” within this file, and what constitutes “interesting data points” within each set.

    Moving on, I see a very vague (so far ...) description of what you actually want to do with each set of data ... however many such sets-of-data there might be ... expressed (as usual) in terms of what you wish to be “the final output.”   Unfortunately, at this point there are simply too-many unanswered questions.

    At this point, I suggest that you add a new post to this thread, including a representative sample of the data records (i.e. enough to clearly show at least two groups of data).   Given this, you will probably get enough specific details to enable you to create the final solution to this problem ... yourself.   There is at this point no question in my mind that Perl can give you what you are looking for, and that it is a very-appropriate power tool by which to do so.