I am trying to create a script that will read multiple text files inside a
specific folder and finds the device names that appears on more than one
file, then display in an excel sheet the device names and the number of times
it found the device name.

Details - I run a daily repot that shows the state of specific devices (
Device name is always the first six characters in a line and the state of the
device is always at the end of the line in between parethesis (state)). I
then export the report as a text file with the name of the day (mon.txt,
tue.txt etc. etc. ) to a folder in my computer. Report files show all Devices
with their repective state. Devices only show once in a report.
What I am trying to do is create a script that I will run on friday that
will check all the text files (monday - friday) then show the devices that
were shown in more than one file with a specific state. I will always look
for the same specific state i,e "(disabled)"

Any help with this script will be appreciated.

Re: script to search text by Pegasus

Pegasus
Fri Mar 07 14:55:32 CST 2008


"Jrex7" <Jrex7@discussions.microsoft.com> wrote in message
news:BEFEC49A-0DD8-4F0E-80B0-47A309CAC30C@microsoft.com...
>I am trying to create a script that will read multiple text files inside a
> specific folder and finds the device names that appears on more than one
> file, then display in an excel sheet the device names and the number of
> times
> it found the device name.
>
> Details - I run a daily repot that shows the state of specific devices (
> Device name is always the first six characters in a line and the state of
> the
> device is always at the end of the line in between parethesis (state)). I
> then export the report as a text file with the name of the day (mon.txt,
> tue.txt etc. etc. ) to a folder in my computer. Report files show all
> Devices
> with their repective state. Devices only show once in a report.
> What I am trying to do is create a script that I will run on friday that
> will check all the text files (monday - friday) then show the devices that
> were shown in more than one file with a specific state. I will always look
> for the same specific state i,e "(disabled)"
>
> Any help with this script will be appreciated.

Let's have a look at what you have so far. It might also be a good
idea to include a sample of your text file.



RE: script to search text by Jrex7

Jrex7
Mon Mar 10 11:15:01 CDT 2008

Here's an sample of one of the text files (monday.txt)
*********************
SV4213 (DISABLED)
SV5921 (DISABLED)
SV4563 (DISABLED)
53 - are currently REMOVED
SV7896 expired 01/29/2008 01:20 (FAILED)
SV7889 expired 01/29/2008 17:43 (PENDING)
SV1236 expired 01/29/2008 16:54 (DISABLED)
SV4652 expires 03/03/2009 09:48 (PENDING)
SV8798 expires 03/03/2009 01:27 (SUSPENDED)
SV3265 expires 03/03/2009 09:48 (DISABLED)
SV5263 expires 03/04/2009 01:15 (DISABLED)
SV4316 expires 03/03/2009 12:51 (FAILED)
DB1234 expires 03/03/2009 10:49 (PENDING)
Number of ACTIVE SERVERS that, as of now:
7 - will expire within 1 week
SV4562 expires 03/05/2008 22:20
DB4569 expires 03/06/2008 18:40
SV7826 expires 03/06/2008 22:38
*************************

As far as the script I dont have anything yet. - I just got started. --
Anyway. I want the script to search for lines tha have state=disabled
then I want to truncate that line to just the first 6 characters (server
name) finally I just want a report only on the servers that showd more than
once after looking at all the text files.

Thank you,



Re: script to search text by ekkehard

ekkehard
Mon Mar 10 12:15:22 CDT 2008

Jrex7 schrieb:
> I am trying to create a script that will read multiple text files inside a
> specific folder and finds the device names that appears on more than one
> file, then display in an excel sheet the device names and the number of times
> it found the device name.
>
> Details - I run a daily repot that shows the state of specific devices (
> Device name is always the first six characters in a line and the state of the
> device is always at the end of the line in between parethesis (state)). I
> then export the report as a text file with the name of the day (mon.txt,
> tue.txt etc. etc. ) to a folder in my computer. Report files show all Devices
> with their repective state. Devices only show once in a report.
> What I am trying to do is create a script that I will run on friday that
> will check all the text files (monday - friday) then show the devices that
> were shown in more than one file with a specific state. I will always look
> for the same specific state i,e "(disabled)"
>
> Any help with this script will be appreciated.
To get you started:

Dim oFS : Set oFS = CreateObject( "Scripting.FileSystemObject" )
Dim sDSDir : sDSDir = oFS.GetAbsolutePathName( ".\disabledsrvs" )
Dim dicSrvs : Set dicSrvs = CreateObject( "Scripting.Dictionary" )
Dim oRE : Set oRE = New RegExp
oRE.Global = True
oRE.Multiline = True
oRE.Pattern = "^(\w{6})\s\(DISABLED\)"

WScript.Echo "------ Files"
Dim oFile
For Each oFile In oFS.GetFolder( sDSDir ).Files
If "txt" = LCase( oFS.GetExtensionName( oFile.Name ) ) Then
WScript.Echo oFile.Name
Dim sAll : sAll = oFile.OpenAsTextStream().ReadAll
Dim oMTS : Set oMTS = oRE.Execute( sAll )
If 0 < oMTS.Count Then
Dim oMT
For Each oMT In oMTS
WScript.Echo " ", oMT.SubMatches( 0 )
dicSrvs( oMT.SubMatches( 0 ) ) = dicSrvs( oMT.SubMatches( 0 ) ) + 1
Next
End If
End If
Next

WScript.Echo "------ Results"
Dim sKey
For Each sKey In dicSrvs.Keys
If 1 < dicSrvs( sKey ) Then
WScript.Echo sKey, dicSrvs( sKey )
End If
Next

Output:

=== fndDisabledSrvs: find disabled servers =====
------ Files
monday.txt
SV4213
SV5921
SV4563
tuesday.txt
SV4213
SV5921
SV1000
------ Results
SV4213 2
SV5921 2
=== fndDisabledSrvs: 0 done (00:00:00) =========

Re: script to search text by ekkehard

ekkehard
Tue Mar 11 07:46:20 CDT 2008

Jrex7 schrieb:
> I am trying to create a script that will read multiple text files inside a
> specific folder and finds the device names that appears on more than one
> file, then display in an excel sheet the device names and the number of times
> it found the device name.
>
> Details - I run a daily repot that shows the state of specific devices (
> Device name is always the first six characters in a line and the state of the
> device is always at the end of the line in between parethesis (state)). I
> then export the report as a text file with the name of the day (mon.txt,
> tue.txt etc. etc. ) to a folder in my computer. Report files show all Devices
> with their repective state. Devices only show once in a report.
> What I am trying to do is create a script that I will run on friday that
> will check all the text files (monday - friday) then show the devices that
> were shown in more than one file with a specific state. I will always look
> for the same specific state i,e "(disabled)"
>
> Any help with this script will be appreciated.

To get you started:

Dim oFS : Set oFS = CreateObject( "Scripting.FileSystemObject" )
Dim sDSDir : sDSDir = oFS.GetAbsolutePathName( ".\disabledsrvs" )
Dim dicSrvs : Set dicSrvs = CreateObject( "Scripting.Dictionary" )
Dim oRE : Set oRE = New RegExp
oRE.Global = True
oRE.Multiline = True
oRE.Pattern = "^(\w{6})\s\(DISABLED\)"

WScript.Echo "------ Files"
Dim oFile
For Each oFile In oFS.GetFolder( sDSDir ).Files
If "txt" = LCase( oFS.GetExtensionName( oFile.Name ) ) Then
WScript.Echo oFile.Name
Dim sAll : sAll = oFile.OpenAsTextStream().ReadAll
Dim oMTS : Set oMTS = oRE.Execute( sAll )
If 0 < oMTS.Count Then
Dim oMT
For Each oMT In oMTS
WScript.Echo " ", oMT.SubMatches( 0 )
dicSrvs( oMT.SubMatches( 0 ) ) = dicSrvs( oMT.SubMatches( 0 ) ) + 1
Next
End If
End If
Next

WScript.Echo "------ Results"
Dim sKey
For Each sKey In dicSrvs.Keys
If 1 < dicSrvs( sKey ) Then
WScript.Echo sKey, dicSrvs( sKey )
End If
Next

output:

=== fndDisabledSrvs: find disables servers ==
------ Files
monday.txt
SV4213
SV5921
SV4563
tuesday.txt
SV4213
SV5921
SV1000
------ Results
SV4213 2
SV5921 2
=== fndDisabledSrvs: 0 done (00:00:00) ======