View the Most Wanted LQ Wiki articles.
 Home Forums HCL Reviews Tutorials Articles Register Search Today's Posts Mark Forums Read
 LinuxQuestions.org A thorny problem about regular expression
 User Name Remember Me? 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

 01-04-2013, 10:16 AM #1 penghcp LQ Newbie   Registered: Mar 2011 Posts: 6 Rep: 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!!!
 01-05-2013, 06:25 PM #2 haertig Senior Member   Registered: Nov 2004 Distribution: Debian, Ubuntu, LinuxMint, Slackware, SysrescueCD Posts: 2,032 Rep: 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)?
 01-05-2013, 06:32 PM #3 haertig Senior Member   Registered: Nov 2004 Distribution: Debian, Ubuntu, LinuxMint, Slackware, SysrescueCD Posts: 2,032 Rep: 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.

 Tags regular expression