LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   regex Perl help (https://www.linuxquestions.org/questions/programming-9/regex-perl-help-363413/)

igotlongestname 09-14-2005 04:30 PM

regex Perl help
 
I am relatively new to perl and trying to extract data off of large output files from a computer simulation model.

I want to search the output file for a certain keyword, then strip off the data from the next line, directly beneath it. For example:

U991 Am992 Am993 Np994 Pu995 U996 Cm997 Am998 12 34 .045 54 .92 453 2321 .433


I would like to search for "Pu995" then strip off the number directly beneath it. I know how to use regex's to find Pu995 uniquely, but not how to find the value for the number beneath it, which changes from computation to computation, but stays in the same "place". Meaning it always occurs there, with the same number of preceeding words or numerical values in front of it. I tried using $. to increase the line number by one, but didn't find that this allowed me access to gather data from the next line, and am not familiar enough to know if there is a quick and clean way to do it or a dirty way. Any help would be appreciated. Thanks!

igotlongestname 09-14-2005 04:32 PM

That's just cute how it screwed up the order ... it's essentially elements in a row listed like this:

Pu994
234

So that elements are on top and their corresponding amounts are listed below them.

chrism01 09-14-2005 07:51 PM

If you read the file line by line, then set a flag to eg 1 when you find Pu995, read the next rec and grab the nth field from it, then reset the flag to 0.


All times are GMT -5. The time now is 06:45 PM.