LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices

Reply
 
Search this Thread
Old 09-14-2005, 04:30 PM   #1
igotlongestname
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
igotlongestname
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:

Pu994
234

So that elements are on top and their corresponding amounts are listed below them.
 
Old 09-14-2005, 07:51 PM   #3
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.5, Centos 5.10
Posts: 16,269

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


Reply


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


All times are GMT -5. The time now is 05:48 AM.

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