Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Parse line from a text file

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,49382
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Parse line from a text file
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 Parse line from a text file - 7/11/2007 7:52:51 PM   
  4scriptmoni


Posts: 208
Score: 0
Joined: 5/3/2007
Status: offline
I am in need of help to better parse lines. Maybe using regular experssions, witch I am not able yet to do :(
Well the line I need to parse is:

1221,INFORMATIONAL,MSExchangeIS Mailbox Store,Wed Jul 11 02:45:28 2007,No User,The database "SG1\Mailbox Store 1 (XOMMST01V01)" has 7457 megabytes of free space after online defragmentation has terminated.      For more information, click http://www.microsoft.com/contentredirect.asp. 

I want to get 2 informations outputed to strA, strB format . I want to get strA = "SG1...01v01) then strB = 7457

here is how I am doing it now, but the problem is not that not always the line is the same so it dosent work always!

      

thanks

_____________________________

Enterprise Microsoft Scripts
Exchange, Login/Logout Monitor,TS, Monitoring, Security, AD, etc...
http://www.felipeferreira.net
 
 
Post #: 1
 
 RE: Parse line from a text file - 7/11/2007 11:24:48 PM   
  mbouchard


Posts: 1916
Score: 16
Joined: 5/15/2003
From: USA
Status: offline
Here is a start, assumes that SG1 is always the start of the section you want and there is only 1 ) in the string

str1 = "1221,INFORMATIONAL,MSExchangeIS Mailbox Store,Wed Jul 11 02:45:28 2007,No User,The database ""SG1\Mailbox Store 1 (XOMMST01V01)"" has 7457 megabytes of free space after online defragmentation has terminated.      For more information, click http://www.microsoft.com/contentredirect.asp."

WScript.Echo Mid(Str1,instr(str1,"SG1"),InStr(str1,")") - instr(str1,"SG1")+1)

_____________________________

Mike

For useful Scripting links see the Read Me First stickey!

Always remember Search is your friend.

(in reply to 4scriptmoni)
 
 
Post #: 2
 
 RE: Parse line from a text file - 7/12/2007 1:10:12 AM   
  dm_4ever


Posts: 2663
Score: 46
Joined: 6/29/2006
From: Orange County, California
Status: offline
RegExp...


      

_____________________________

dm_4ever

My philosophy: K.I.S.S - Keep It Simple Stupid
Read Me: http://www.visualbasicscript.com/m_24727/tm.htm
Frequently Asked Stuff: http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to 4scriptmoni)
 
 
Post #: 3
 
 RE: Parse line from a text file - 7/12/2007 1:10:52 AM   
  4scriptmoni


Posts: 208
Score: 0
Joined: 5/3/2007
Status: offline
thanks I will try that, but yes the string usally starts with "SG.... X"  but finishes in different ways not always a ) but it is always between  " "
and then the second part is alwys a number after the word "has" and before word "megabytes" ex: has 7457 megabytes


thanks

_____________________________

Enterprise Microsoft Scripts
Exchange, Login/Logout Monitor,TS, Monitoring, Security, AD, etc...
http://www.felipeferreira.net

(in reply to mbouchard)
 
 
Post #: 4
 
 RE: Parse line from a text file - 7/17/2007 7:41:34 PM   
  4scriptmoni


Posts: 208
Score: 0
Joined: 5/3/2007
Status: offline
Wow it worked perfect! I love those Regular Expressions, wish I knew how to use it... mayb a link with some tips to it?
Like this Pattern:
RegEx.Pattern = "database\s""(.*)""\shas ([0-9]+)"


strToParse "The database "SG1\Mailbox Store 1 (XSDMST01V01)" has 7457 megabytes of free space after online defragmentation has terminated."


databse\s""(.*)  What does it do???
\shas ([0-9]+)" after has get all number 0 to 9 ?

thanks man

_____________________________

Enterprise Microsoft Scripts
Exchange, Login/Logout Monitor,TS, Monitoring, Security, AD, etc...
http://www.felipeferreira.net

(in reply to dm_4ever)
 
 
Post #: 5
 
 RE: Parse line from a text file - 7/18/2007 1:10:39 AM   
  dm_4ever


Posts: 2663
Score: 46
Joined: 6/29/2006
From: Orange County, California
Status: offline
database = taken literally
\s = a single space
"" = look for "
() around the .* = defines a group
. = means any character
* = means the character can show up 0 or more times
"" = look for " again
\s = a single space again
has = taken literally again
() = define another group
[0-9] = any number between 0 and 9
+ = occurs 1 or more times


I like this cheat sheet: http://www.ilovejackdaniels.com/regular_expressions_cheat_sheet.pdf
Another reference: http://www.regular-expressions.info/reference.html
And Another:  http://msdn2.microsoft.com/en-us/library/kxt24tyh.aspx

_____________________________

dm_4ever

My philosophy: K.I.S.S - Keep It Simple Stupid
Read Me: http://www.visualbasicscript.com/m_24727/tm.htm
Frequently Asked Stuff: http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to 4scriptmoni)
 
 
Post #: 6
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Parse line from a text file Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts