LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices

Reply
 
Search this Thread
Old 01-04-2013, 09:16 AM   #1
penghcp
LQ Newbie
 
Registered: Mar 2011
Posts: 6

Rep: Reputation: 0
A thorny problem about regular expression


Hi guys:
I have a thorny problem about regular expression. In my folder there are many TXTs contain datas like this:

Alpha occ. eigenvalues -- -0.28771 -0.28551 -0.28076 -0.26640 -0.25753
Alpha occ. eigenvalues -- -0.24934 -0.23537 -0.20864 -0.20362 -0.18781
Alpha occ. eigenvalues -- -0.18499
Alpha virt. eigenvalues -- -0.08600 -0.07990 -0.05849 -0.05466 -0.02270
Alpha virt. eigenvalues -- -0.01590 0.00041 0.00439 0.03404 0.03475
Alpha virt. eigenvalues -- 0.04147 0.04164 0.04671 0.05375 0.06108

or

Alpha occ. eigenvalues -- -0.29503 -0.29464 -0.28431 -0.27790 -0.27478
Alpha occ. eigenvalues -- -0.26611 -0.26548 -0.24146 -0.22199 -0.22060
Alpha occ. eigenvalues -- -0.22053 -0.17924 -0.17368
Alpha virt. eigenvalues -- -0.09805 -0.09012 -0.04761 -0.04677 -0.04593
Alpha virt. eigenvalues -- -0.02608 -0.00336 0.00144 0.01824 0.02201
Alpha virt. eigenvalues -- 0.03658 0.03842 0.03912 0.04273 0.04860.

I need extract three values before "Alpha virt. eigenvalues"(ie: -0.20362 -0.18781 -0.18499 )
and three values after "Alpha virt. eigenvalues" (ie: -0.08600 -0.07990 -0.05849 )
PS: 1. The line numbers of lines contain "Alpha virt. eigenvalues" of these TXTs are different from each other !
2. The "Alpha virt. eigenvalues" phrase can be find firstly in each TXT if you use the search tools.
3. There are different values after the last "Alpha occ. eigenvalues".
Is there some smart methods to do this ? After all, I need dispose thousand TXTs.

Thanks very much and Looking forward your replay!!!
 
Old 01-05-2013, 05:25 PM   #2
haertig
Senior Member
 
Registered: Nov 2004
Distribution: Debian, Ubuntu, LinuxMint, Slackware, SysrescueCD
Posts: 2,004

Rep: Reputation: 304Reputation: 304Reputation: 304Reputation: 304
Are you REQUIRING that this be done using only a regular expression (tough to impossible)? I certainly wouldn't attempt it as a pure-REGEX assignment. Or are you willing to consider a bit of scripting to help get to your end result (e.g., something written in PERL)?
 
Old 01-05-2013, 05:32 PM   #3
haertig
Senior Member
 
Registered: Nov 2004
Distribution: Debian, Ubuntu, LinuxMint, Slackware, SysrescueCD
Posts: 2,004

Rep: Reputation: 304Reputation: 304Reputation: 304Reputation: 304
Also, just because I have seen this type of question before - so take no offense - Is this a real world problem you are trying to solve, or a homework assignment you are looking to have someone do for you? Many here are willing to help with real world problems, but not do homework assignments. I ask simply because your request is a pretty odd one that you wouldn't often run into (sorry to have to say that), and sometimes these "odd ones" turn out to be contrived homework assignments.
 
  


Reply

Tags
regular expression


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
[SOLVED] Regular Expression Problem rm_-rf_windows Linux - General 25 03-17-2012 05:22 PM
[SOLVED] problem with regular expression ashok.g Programming 2 12-30-2009 06:05 AM
regular expression problem sancho1980 Programming 10 06-08-2009 07:26 AM
perl regular expression problem true_atlantis Programming 4 05-27-2009 06:35 AM
Regular expression problem raghu123 Programming 11 10-12-2008 07:17 AM


All times are GMT -5. The time now is 11:41 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