AutoHotkey Community

It is currently May 25th, 2012, 5:40 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 11 posts ] 
Author Message
PostPosted: May 15th, 2007, 8:21 am 
Offline

Joined: December 7th, 2005, 8:29 am
Posts: 345
Hi,

i want to capture and store hard drive s.m.a.r.t data into subpatterns

i tried using an array but it didnt work universally for every line.

Code:
ID   Attribute                  Type  Threshold Value Worst        Raw Status
---- -------------------------- ----- --------- ----- ----- ---------- --------
[01] Raw Read Error Rate        Prefailure   51   200   200         11 OK
[03] Spin Up Time               Prefailure   21   188   187       1558 OK
[04] Start/Stop Count           Advisory      0   100   100        673 OK
[05] Reallocated Sector Count   Prefailure  140   200   200          0 OK
[07] Seek Error Rate            Advisory      0   200   200          0 OK
[09] Power On Hours Count       Advisory      0    99    99       1202 OK
[0A] Spin Retry Count           Advisory      0   100   100          0 OK
[0B] Calibration Retry Count    Advisory      0   100   100          0 OK
[0C] Power Cycle Count          Advisory      0   100   100        554 OK
[C0] Power-Off Park Count       Advisory      0   200   200        451 OK
[C1] Load/Unload Cycle Count    Advisory      0   190   190      31415 OK
[C2] Drive Temperature          Advisory      0   110   105         37 OK
[C4] Re-Allocated Data Count    Advisory      0   200   200          0 OK
[C5] Pending Sector Count       Advisory      0   200   200          0 OK
[C6] UnCorrectable Sector Count Advisory      0   200   200          0 OK
[C7] CRC Error Count            Advisory      0   200   200          0 OK
[C8] Write Error Rate           Advisory      0   200   200          0 OK


thanks
Twhyman


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 15th, 2007, 9:34 am 
Since your data seems to be well aligned, I believe parsing with SubStr is an easy way.
Otherwise, you can use stuff like: ".{4} .{50}" and so on, to get the split in one go.


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: May 19th, 2007, 7:32 am 
Offline

Joined: December 7th, 2005, 8:29 am
Posts: 345
helpy,

can you give an example cause i dont realy follow you?

thanks
twhyman


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 19th, 2007, 10:14 am 
Offline

Joined: March 24th, 2007, 8:10 pm
Posts: 39
Hi,

Helpy means that you can use the fact that every part of your data can be considered to start at a particular column/position. Discarding the header rows, your data follows this pattern:
ID: starts at position 2, has a length of 2
Attribute: starts at position 6, has a length of 26
Type: starts at position 33, has a length of 10
Threshold: starts at position 44, has a length of 4
Value: starts at position 49, has a length of 5
Worst: starts at position 55, has a length of 5
Raw: starts at position 61, has a length of 10
Status: starts at position 72, has a length of 8

Each one of these can be directly translated into a SubStr() or a StringMid command. Then you'll have to deal with the spaces left and right.

On the other side, a RegEx would allow you to process each line with a single command (including the space removal).

_________________
Regards,
Antonio


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 19th, 2007, 11:51 am 
Offline

Joined: December 27th, 2005, 1:46 pm
Posts: 6837
Location: France (near Paris)
atnbueno wrote:
Then you'll have to deal with the spaces left and right.
Not if he uses StringMid with AutoTrim on (the default).

_________________
Image vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 19th, 2007, 12:50 pm 
Offline

Joined: March 24th, 2007, 8:10 pm
Posts: 39
You're right. I forgot about AutoTrim.

_________________
Regards,
Antonio


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 19th, 2007, 4:23 pm 
Offline

Joined: December 7th, 2005, 8:29 am
Posts: 345
thanks for the help guys, but i am looking for a single regex line to procces the lines.

i tried for hours to get it but with no succes :(

can you help me with the regex (maybe PhiLho the RegEx master :))?

Thanks
Twhyman


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 19th, 2007, 5:45 pm 
Offline

Joined: December 27th, 2005, 1:46 pm
Posts: 6837
Location: France (near Paris)
OK, it isn't so hard, just need to be clean:
Code:
lines =
(
ID   Attribute                  Type  Threshold Value Worst        Raw Status
---- -------------------------- ----- --------- ----- ----- ---------- --------
[01] Raw Read Error Rate        Prefailure   51   200   200         11 OK
[03] Spin Up Time               Prefailure   21   188   187       1558 OK
[04] Start/Stop Count           Advisory      0   100   100        673 OK
[05] Reallocated Sector Count   Prefailure  140   200   200          0 OK
[07] Seek Error Rate            Advisory      0   200   200          0 OK
[09] Power On Hours Count       Advisory      0    99    99       1202 OK
[0A] Spin Retry Count           Advisory      0   100   100          0 OK
[0B] Calibration Retry Count    Advisory      0   100   100          0 OK
[0C] Power Cycle Count          Advisory      0   100   100        554 OK
[C0] Power-Off Park Count       Advisory      0   200   200        451 OK
[C1] Load/Unload Cycle Count    Advisory      0   190   190      31415 OK
[C2] Drive Temperature          Advisory      0   110   105         37 OK
[C4] Re-Allocated Data Count    Advisory      0   200   200          0 OK
[C5] Pending Sector Count       Advisory      0   200   200          0 OK
[C6] UnCorrectable Sector Count Advisory      0   200   200          0 OK
[C7] CRC Error Count            Advisory      0   200   200          0 OK
[C8] Write Error Rate           Advisory      0   200   200          0 OK
)
Loop Parse, lines, `n, `r
{
   fp := RegExMatch(A_LoopField, "\[(?'ID'..)]\s(?'Attribute'.{27})(?'Type'\w+)\s+(?'Threshold'\d+)\s+(?'Value'\d+)\s+(?'Worst'\d+)\s+(?'Raw'\d+)\s+(?'Status'\w+)", field)
   If (fp > 0)
   {
      fieldAttribute = %fieldAttribute% ; Trim spaces
      MsgBox ID: %fieldID% Attribute: %fieldAttribute% Type: %fieldType% Threshold: %fieldThreshold% Value: %fieldValue% Worst: %fieldWorst% Raw: %fieldRaw% Status: %fieldStatus%
   }
}
[EDIT] Took in account atnbueno's remarks.

_________________
Image vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")


Last edited by PhiLho on May 19th, 2007, 8:32 pm, edited 2 times in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 19th, 2007, 7:31 pm 
Offline

Joined: March 24th, 2007, 8:10 pm
Posts: 39
There's a
Code:
(?'Threshold'\d+)\s+

missing in the RegEx and I would left the square brackets outside the ID :) but other than that, thanks for the code, a very clarifying example.

I hadn't noticed the problem with "Attribute" and the spaces :oops:

_________________
Regards,
Antonio


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 19th, 2007, 8:33 pm 
Offline

Joined: December 27th, 2005, 1:46 pm
Posts: 6837
Location: France (near Paris)
Good remarks, thanks. I corrected the code accordingly.

_________________
Image vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 20th, 2007, 2:04 am 
Offline

Joined: December 7th, 2005, 8:29 am
Posts: 345
thanks alot guys for the help :)


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 11 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: alanofoz, Bing [Bot], Cerberus, LazyMan, lblb, poserpro, Yahoo [Bot] and 19 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group