LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
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 02-02-2016, 03:31 PM   #1
sumncguy
Member
 
Registered: Jun 2013
Posts: 76

Rep: Reputation: Disabled
Regular Expressions. Detect status across multiple lines


This is a real world problem.

I need to check the status of power supplies.

An example of the data .... Note when quoted here the leading white space on the lines Fan.* through Thermal.* are stripped.

Quote:
SYS PS1 is present.
Fan status: Normal
Input Voltage status: Normal
DC Output Voltage status: Normal
Type: AC
Thermal status: Normal

SYS PS2 is absent.
The RE Im using .. its just ugly
Code:
\s+Fan.*:\sNormal\s+Input.*:\sNormal\s+DC.*:\sNormal\s+Type.*\s+Therm.*:\sNormal
Is there a better way to do this ?
 
Old 02-02-2016, 04:02 PM   #2
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=15, FreeBSD_12{.0|.1}
Posts: 6,263
Blog Entries: 24

Rep: Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194
Use CODE tags instead of QUOTEs and it will preserve the whitespace.

Also, just to be very clear about what you want to do, give an example of the input plus an example of the desired output.

From that someone can help much more effectively.
 
Old 02-02-2016, 05:35 PM   #3
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,125

Rep: Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120
There is always a better way.

Multiple test in long data eventually always gets ugly. If you don't like the ugliosity, try ANDing multiple tests - might be more readable.
 
Old 02-02-2016, 06:29 PM   #4
danielbmartin
Senior Member
 
Registered: Apr 2010
Location: Apex, NC, USA
Distribution: Mint 17.3
Posts: 1,881

Rep: Reputation: 660Reputation: 660Reputation: 660Reputation: 660Reputation: 660Reputation: 660
Quote:
Originally Posted by sumncguy View Post
Is there a better way to do this ?
To do what? Your problem statement is opaque and lacks an example of the desired output. You provided a sample RegExp but didn't show how you are using it. sed? grep? Something else?

Daniel B. Martin
 
Old 02-02-2016, 11:52 PM   #5
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,006

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
ditto to all of the above. Hard to assist without even knowing what command / language you are using?
 
  


Reply



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
python: passing functions or unevaluated code with multiple lines or expressions stateless Programming 1 11-30-2013 10:38 PM
export multiple executable paths in a parent directory using regular expressions? lmcilwain Linux - General 2 10-03-2012 09:01 AM
Regular Expressions Wim Sturkenboom Programming 10 11-19-2009 01:21 AM
help with regular expressions mariogarcia Linux - Software 3 01-28-2009 03:23 AM
Unpacking multiple ZIP files (regular expressions) Ariod Linux - Newbie 1 02-24-2006 12:48 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

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

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration