Help answer threads with 0 replies.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 09-14-2005, 04:30 PM   #1
LQ Newbie
Registered: Sep 2005
Posts: 2

Rep: Reputation: 0
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!
Old 09-14-2005, 04:32 PM   #2
LQ Newbie
Registered: Sep 2005
Posts: 2

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


So that elements are on top and their corresponding amounts are listed below them.
Old 09-14-2005, 07:51 PM   #3
LQ Guru
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.9, Centos 7.3
Posts: 17,396

Rep: Reputation: 2395Reputation: 2395Reputation: 2395Reputation: 2395Reputation: 2395Reputation: 2395Reputation: 2395Reputation: 2395Reputation: 2395Reputation: 2395Reputation: 2395
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.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
perl - regex - negation beebop Programming 9 06-19-2005 08:25 PM
perl regex matching exodist Programming 2 11-15-2004 10:50 PM
perl: using 'substr' in regex ananthbv Programming 5 11-03-2004 01:58 AM
Regex help needed in perl Dr Twox Programming 2 08-07-2004 05:58 AM
HELP ->PERL regex is kick'n my a... prisoner Programming 2 03-18-2004 09:49 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:33 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration