topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • Wednesday December 11, 2024, 10:51 am
  • Proudly celebrating 15+ years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: IDEA: Search Txt files export data  (Read 8577 times)

Earthcoder

  • Participant
  • Joined in 2007
  • *
  • Posts: 48
    • View Profile
    • Donate to Member
IDEA: Search Txt files export data
« on: April 11, 2007, 04:17 AM »
Hello,

Wondered if you can help, I am looking for a script or program, that will search a folder full of text files, then pull data lines from txt file and place into a database or CSV file.

Example of a txt file (there 2,000 files)

System Snapshot - Tue 10/04/2007  8:46:05.46

Last User:         s2101389
System Name:         C09730
System Manufacturer:      Viglen                         
System Model:         GENIE D865GLC                 
BIOS Manufacturer:      Intel Corp.
BIOS Version:         BIOS Date: 01/22/04 09:53:47 Ver: 08.00.10
BIOS Serial Number:      1739056                       
Processor:             Intel(R) Pentium(R) 4 CPU 2.80GHz 2793MHz
OS Name:         Microsoft Windows 2000 Professional
OS Version:         5.0.2195
Service Pack:         4
Windows Directory:      C:\WINNT
Locale:            English United States
Total Physical Memory:      511MB
Free Physical Memory:      160MB
Total Disk Space (SystemDrive):   33503MB
Free Disk Space (SystemDrive):   11043MB

Internet Explorer Version:   6.0.2800.1106
Current Users Profile:      C:\Documents and Settings\s2101307


Windows 2000 IP Configuration
Ethernet adapter Local Area Connection:

   Connection-specific DNS Suffix  . : chelt.local
   Description . . . . . . . . . . . : Intel(R) PRO/100 VE Network Connection
   Physical Address. . . . . . . . . : 00-0C-F1-E1-41-81

   
   IP Address. . . . . . . . . . . . : 10.59.11.241




   Lease Obtained. . . . . . . . . . : 10 April 2007 08:41:48

   Lease Expires . . . . . . . . . . : 18 April 2007 08:41:48



Software Installed

List of all software installed


Printer Connections



Server name
Printer name Microsoft Office Document Image Writer
Share name
Driver name Microsoft Office Document Image Writer Driver
Port name Microsoft Document Imaging Writer Port:
Location
Print processor ModiPrint
Data type RAW
Attributes 64
Default priority 0
Status Unknown
Average pages per minute 0

Server name
Printer name \\c12214\ICT RICOH Aficio 2020D PCL 6
Share name ICT OFFICE
Driver name RICOH Aficio 2020D PCL 6
Port name EQ_IP_10.59.1.233
Location PARK, LC004, ICT Office
Print processor WinPrint
Data type RAW
Attributes 540
Default priority 0
Start time 00h00
Until time 00h00
Status Unknown
Average pages per minute 0



Basically What i wanted, is a script or program that searches this files and caprures the follow info in a csv  - The whole lines.
System Snapshot:
Last User:
System Name:
Processor:
Total Physical Memory:      
Free Physical Memory:      
Total Disk Space (SystemDrive):   
Free Disk Space (SystemDrive):   
Physical Address. . . . . . . . . :
IP Address. . . . . . . . . . . . :
Software Installed: (List in one field spaced)
Printer name:

If possiable all the required names as fields then all the details in one csv, If not just csv per file.

I been searching net all morning for something that would do it but cant find one.

If not possiable please let me know


tinjaw

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 1,927
    • View Profile
    • Donate to Member
Re: IDEA: Search Txt files export data
« Reply #1 on: April 11, 2007, 08:33 AM »
Earthcoder,

 :huh: Please provide a sample of what the CSV files should look like based on the TXT file you provided. That might help to scope out the complexity of what is requested.

Earthcoder

  • Participant
  • Joined in 2007
  • *
  • Posts: 48
    • View Profile
    • Donate to Member
Re: IDEA: Search Txt files export data
« Reply #2 on: April 11, 2007, 11:50 AM »
Would be ideal if all files were added to one csv EG:
System Snapshot:,Last User:,System Name:,Processor: ,Total Physical Memory:      ,Free Physical Memory:      ,Total Disk Space,Free Disk Space,Physical Address.,IP Address.,Software Installed: ,Printer name:
Date,s2101307,c09730,    Intel(R) Pentium(R) 4 CPU 2.80GHz 2793MHz,511MB,160MB,33503MB,11043MB,00-0C-F1-E1-41-81,10.59.11.241,office PDF Photoshop etc, \\c12214\ICT RICOH Aficio 2020D PCL 6
next text file,next text file,next text file,next text file,next text file,next text file,next text file,next text file,next text file,next text file,next text file,next text file

Or if Single Just ignore Next text file

Or anyother way u can suggest would be good.

I run a Inventory system of computers on the network, and before i had to do them all manually, importing into a sql database, But thought it would be easier if just used a system snapshot, then import into the sql file, every week or too with the latest updates.

Csv is easy to work with, But access or Sql can be ok too, just a database of all the content of the files.

If there no way around this then ill have to think of somthing else.

tinjaw

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 1,927
    • View Profile
    • Donate to Member
Re: IDEA: Search Txt files export data
« Reply #3 on: April 11, 2007, 12:08 PM »
What you are asking for is probably doable, but would require a lot of hard coding to get only the info you wanted out of the report. (From just a quick look at things.) How much leeway do you have? You could use WMI and gather the info that you wanted, even remotely, and put it in a CSV or straight into the SQL server.

Also, have you looked into freeware tools like WinAudit and Belarc Advisor?
« Last Edit: April 11, 2007, 12:14 PM by tinjaw »

e_murf1

  • Participant
  • Joined in 2007
  • *
  • default avatar
  • Posts: 4
    • View Profile
    • Donate to Member
Re: IDEA: Search Txt files export data
« Reply #4 on: April 11, 2007, 01:08 PM »
Not exactly a piece of beauty but it appears to do the trick for me. Have you an FTP that I can upload the .exe and xml to? My webmail might let me e-mail it to you, work mail will definitely block it.

Eoghan

Imports System.IO
Imports System.Xml

Public Class Form1
    Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer. 
    'Do not modify it using the code editor.
    Friend WithEvents InDirBut As System.Windows.Forms.Button
    Friend WithEvents OutDirBut As System.Windows.Forms.Button
    Friend WithEvents InDirTB As System.Windows.Forms.TextBox
    Friend WithEvents OutDirTB As System.Windows.Forms.TextBox
    Friend WithEvents StartBut As System.Windows.Forms.Button
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.InDirBut = New System.Windows.Forms.Button
        Me.OutDirBut = New System.Windows.Forms.Button
        Me.InDirTB = New System.Windows.Forms.TextBox
        Me.OutDirTB = New System.Windows.Forms.TextBox
        Me.StartBut = New System.Windows.Forms.Button
        Me.SuspendLayout()
        '
        'InDirBut
        '
        Me.InDirBut.Location = New System.Drawing.Point(8, 8)
        Me.InDirBut.Name = "InDirBut"
        Me.InDirBut.Size = New System.Drawing.Size(88, 24)
        Me.InDirBut.TabIndex = 0
        Me.InDirBut.Text = "Input Folder"
        '
        'OutDirBut
        '
        Me.OutDirBut.Location = New System.Drawing.Point(8, 32)
        Me.OutDirBut.Name = "OutDirBut"
        Me.OutDirBut.Size = New System.Drawing.Size(88, 24)
        Me.OutDirBut.TabIndex = 1
        Me.OutDirBut.Text = "Output Folder"
        '
        'InDirTB
        '
        Me.InDirTB.Location = New System.Drawing.Point(96, 8)
        Me.InDirTB.Name = "InDirTB"
        Me.InDirTB.Size = New System.Drawing.Size(664, 20)
        Me.InDirTB.TabIndex = 2
        Me.InDirTB.Text = "E:\test"
        '
        'OutDirTB
        '
        Me.OutDirTB.Location = New System.Drawing.Point(96, 32)
        Me.OutDirTB.Name = "OutDirTB"
        Me.OutDirTB.Size = New System.Drawing.Size(664, 20)
        Me.OutDirTB.TabIndex = 3
        Me.OutDirTB.Text = "E:\test"
        '
        'StartBut
        '
        Me.StartBut.Location = New System.Drawing.Point(320, 64)
        Me.StartBut.Name = "StartBut"
        Me.StartBut.Size = New System.Drawing.Size(96, 24)
        Me.StartBut.TabIndex = 4
        Me.StartBut.Text = "Start"
        '
        'Form1
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(768, 102)
        Me.Controls.Add(Me.StartBut)
        Me.Controls.Add(Me.OutDirTB)
        Me.Controls.Add(Me.InDirTB)
        Me.Controls.Add(Me.OutDirBut)
        Me.Controls.Add(Me.InDirBut)
        Me.Name = "Form1"
        Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
        Me.Text = "Parser Thing"
        Me.ResumeLayout(False)

    End Sub

#End Region

    Dim AL As New ArrayList
    Dim ARR(,) As String
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Try
            'xml document object
            Dim xd As New Xml.XmlDocument

            'load the xml file
            xd.Load(Application.StartupPath & "\IncludeTheseNamesInCSV.xml")
            Dim Node As XmlNode = xd.SelectSingleNode("//INCLUDE")
            Dim ChildNode As XmlNode

            For Each ChildNode In Node
                AL.Add(ChildNode.InnerText)
            Next

            ReDim ARR(AL.Count - 1, 0)
            Dim s As String
            Dim i As Integer = 0
            For Each s In AL
                ARR(i, 0) = s
                i += 1
            Next

        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try

    End Sub

    Private Sub StartBut_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles StartBut.Click
        Try
            If InDirTB.Text = "" Then
                MsgBox("Input directory does not exist")
                Exit Sub
            End If
            Dim dirIn As New DirectoryInfo(InDirTB.Text.Trim)
            If dirIn.Exists = False Then
                MsgBox("Input directory does not exist")
                Exit Sub
            End If

            If OutDirTB.Text = "" Then
                MsgBox("Output directory does not exist")
                Exit Sub
            End If
            Dim dirOut As New DirectoryInfo(InDirTB.Text.Trim)
            If dirOut.Exists = False Then
                MsgBox("Output directory does not exist")
                Exit Sub
            End If



            Dim fi As FileInfo
            For Each fi In dirIn.GetFiles
                If fi.Extension = ".txt" Then
                    If CheckForRequiredText(fi.FullName) = True Then
                        GetRequiredText(fi.FullName)
                    End If
                End If
            Next

            Dim i As Integer = 0
            Dim FileOut As New FileInfo(dirOut.FullName & "\Output-" & i & ".csv")
            While FileOut.Exists = True
                i = i + 1
                FileOut = New FileInfo(dirOut.FullName & "\Output-" & i & ".csv")
            End While



            Dim Count1 As Integer = 0
            Dim Count2 As Integer = 0
            Dim LineOut As String = ""
            Dim SW As New StreamWriter(dirOut.FullName & "\Output-" & i & ".csv")
            For Count1 = 0 To ARR.GetUpperBound(1)
                LineOut = ""
                For Count2 = 0 To ARR.GetUpperBound(0)
                    LineOut = LineOut & ARR(Count2, Count1) & ","
                Next
                SW.WriteLine(LineOut)
            Next
            SW.Close()

            MsgBox("FINISHED")
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
    End Sub

    Private Function CheckForRequiredText(ByVal FileIn As String) As Boolean
        Try

            Dim oFileIn As String
            Dim SR As New StreamReader(FileIn)
            oFileIn = SR.ReadToEnd
            SR.Close()

            Dim s As String
            For Each s In AL
                If InStr(oFileIn, s) = 0 Then Return False
            Next

            Return True
        Catch ex As Exception
            MsgBox(ex.ToString)
            Return False
        End Try
    End Function

    Private Function GetRequiredText(ByVal FileIn As String) As Boolean
        Try
            ReDim Preserve ARR(ARR.GetUpperBound(0), ARR.GetUpperBound(1) + 1)
            Dim oLineIn As String
            Dim SR As New StreamReader(FileIn)
            oLineIn = SR.ReadLine
            While Not (oLineIn Is Nothing)
                Dim i As Integer = 0
                Dim s As String
                For Each s In AL
                    If InStr(oLineIn, s) > 0 Then
                        Dim str As String = oLineIn
                        str = Replace(str, s, "")
                        str = str.Trim
                        ARR(i, ARR.GetUpperBound(1)) = str
                    End If
                    i += 1
                Next
                oLineIn = SR.ReadLine
            End While
            SR.Close()

            Return True
        Catch ex As Exception
            MsgBox(ex.ToString)
            Return False
        End Try
    End Function

    Private Sub InDirBut_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles InDirBut.Click
        Try
            Dim dialog As New FolderBrowserDialog
            Dim Result As DialogResult = dialog.ShowDialog()
            If Result <> DialogResult.OK Then Exit Sub
            If dialog.SelectedPath.ToString = "" Then Exit Sub
            InDirTB.Text = dialog.SelectedPath.ToString
            dialog.Dispose()
            dialog = Nothing
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
    End Sub

    Private Sub OutDirBut_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OutDirBut.Click
        Try
            Dim dialog As New FolderBrowserDialog
            Dim Result As DialogResult = dialog.ShowDialog()
            If Result <> DialogResult.OK Then Exit Sub
            If dialog.SelectedPath.ToString = "" Then Exit Sub
            OutDirTB.Text = dialog.SelectedPath.ToString
            dialog.Dispose()
            dialog = Nothing
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
    End Sub


End Class

Earthcoder

  • Participant
  • Joined in 2007
  • *
  • Posts: 48
    • View Profile
    • Donate to Member
Re: IDEA: Search Txt files export data
« Reply #5 on: April 12, 2007, 01:36 AM »
Not exactly a piece of beauty but it appears to do the trick for me. Have you an FTP that I can upload the .exe and xml to? My webmail might let me e-mail it to you, work mail will definitely block it.

my email is [email protected]
uploading i guess one of them free sites like: http://www.yousendit.com/

Or gmail drive.

Or attach to thread if under 8000 KB
« Last Edit: April 12, 2007, 01:45 AM by Earthcoder »

Earthcoder

  • Participant
  • Joined in 2007
  • *
  • Posts: 48
    • View Profile
    • Donate to Member
Re: IDEA: Search Txt files export data
« Reply #6 on: April 12, 2007, 05:51 AM »
What you are asking for is probably doable, but would require a lot of hard coding to get only the info you wanted out of the report. (From just a quick look at things.) How much leeway do you have? You could use WMI and gather the info that you wanted, even remotely, and put it in a CSV or straight into the SQL server.

Also, have you looked into freeware tools like WinAudit and Belarc Advisor?
tried the freeware tools, not so good, As i dont wanna go and vist 2,000 computers to run it.

If the whole text file was Made into a csv would be ok, would just ignore fields when importing into sql or access


e_murf1

  • Participant
  • Joined in 2007
  • *
  • default avatar
  • Posts: 4
    • View Profile
    • Donate to Member
Re: IDEA: Search Txt files export data
« Reply #7 on: April 12, 2007, 06:41 AM »
You can add extra entrys in the XML to pull the info for the other lines. It will search each file for a line containing each entry, if the file does not contain all of the entrys it ignores it. It is case sensitive. If it is nearly right tell me what changes you need & I'll try & get it in today.

Eoghan.

e_murf1

  • Participant
  • Joined in 2007
  • *
  • default avatar
  • Posts: 4
    • View Profile
    • Donate to Member
Re: IDEA: Search Txt files export data
« Reply #8 on: April 12, 2007, 08:01 AM »
I added a textbox which will tell you if any of the files in the folder don't contain all of the info you want to pull from them, progress bar to let you know how its doing & an option to switch of the case sensitivity.

Eoghan

Earthcoder

  • Participant
  • Joined in 2007
  • *
  • Posts: 48
    • View Profile
    • Donate to Member
Re: IDEA: Search Txt files export data
« Reply #9 on: April 12, 2007, 09:17 AM »
Wow, Thats dead good, Thanks so much, grabs the data that i need very well.

1 thing, Some errors come up saying G:\inv\C02348.txt - was missing a value for 'INTERNET EXPLORER VERSION:'
when it outputs, it skips them out in the csv, is there away of adding them but leaving the field blank

It dont matter if not.
« Last Edit: April 12, 2007, 09:24 AM by Earthcoder »

e_murf1

  • Participant
  • Joined in 2007
  • *
  • default avatar
  • Posts: 4
    • View Profile
    • Donate to Member
Re: IDEA: Search Txt files export data
« Reply #10 on: April 12, 2007, 09:21 AM »
No prob, glad it worked ok for you.