views:

527

answers:

4

I have read the suggestion listed here.

http://stackoverflow.com/questions/418916/delete-certain-lines-in-a-txt-file-via-a-batch-file

The batch file solution seems to work untill i get to about 5 ignore conditiobal strings and then the output starts to ignore very large sections of the text files(s) even things it shouldn't.

Basically I have a bunch of Windows systeminfo (run > cmd > systeminfo) parses. If you run the system info util you will see several lines there (200+). I want a way to run through them (directory at a time hopefully) and only keep or parse out about the 10 lines that matter (cpu speed, ram amt, etc etc).

Like I said I tried the solution above and it looked great until I got past a few ignore strings and all of a sudden it just started ignoring almost everything.

Does anyone have a suggestion? Or even an Idea as to what I was doing wrong?

This is what I got up to before I realized that lines that should not have been deleted were not being printed.

type *.txt | findstr /v "OS Manufacturer:" | findstr /v "OS Configuration:" | findstr /v "OS Build Type:" | findstr /v "Product ID:" | findstr /v "Original Install Date:" | findstr /v "System Up Time:" | findstr /v "System type:" | findstr /v "BIOS Version:" | findstr /v "Windows Directory:" | findstr /v "System Directory:" | findstr /v "Boot Device:" | findstr /v "System Locale:" | findstr /v "Input Locale:" | findstr /v "Time Zone:" | findstr /v "Available Physical Memory:" | findstr /v "Virtual Memory: Max Size:" | findstr /v "Virtual Memory: Available:" | findstr /v "Virtual Memory: In Use:" | findstr /v "Page File Location(s):" | findstr /v "Domain:" | findstr /v "Logon Server:" | findstr /v "Hotfix(s):" | findstr /v "NetWork Card(s):" | findstr /v "Registered Owner:" | findstr /v "Registered Organization:"  > c:\zzz\final.txt

pause

A: 

Odds are your problem is simply that your command line is too long. Try breaking the filtering up in several parts, with intermediate files in between.

Stu
There are no variable expansions which could cause this and the maximum command-line length limit in cmd is 8190 characters.
Joey
A: 

please get a proper tool for parsing text. if you can afford to use tools like gawk (for windows), here's how you can do it , EASILY.

C:\test>systeminfo | gawk -F":" "/BIOS|Processor|<things i want>/{print $2}"

or if you can't afford to download stuff, M$ provided us with vbscript, which is way better than batch for doing things like this. Here's an example and not exhaustive solution

Set dtmConvertedDate = CreateObject("WbemScripting.SWbemDateTime")    
strComputer = "."
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")    
Set colOperatingSystems = objWMIService.ExecQuery("Select * from Win32_OperatingSystem")
For Each objOperatingSystem in colOperatingSystems
    Wscript.Echo "Boot Device: " & objOperatingSystem.BootDevice
    Wscript.Echo "Build Number: " & objOperatingSystem.BuildNumber
    Wscript.Echo "Build Type: " & objOperatingSystem.BuildType
    Wscript.Echo "Caption: " & objOperatingSystem.Caption
    Wscript.Echo "Code Set: " & objOperatingSystem.CodeSet
    Wscript.Echo "Country Code: " & objOperatingSystem.CountryCode
    Wscript.Echo "Debug: " & objOperatingSystem.Debug
    Wscript.Echo "Install Date: " & dtmInstallDate 
    Wscript.Echo "Licensed Users: " & objOperatingSystem.NumberOfLicensedUsers
    Wscript.Echo "Organization: " & objOperatingSystem.Organization
    Wscript.Echo "OS Language: " & objOperatingSystem.OSLanguage
    Wscript.Echo "OS Product Suite: " & objOperatingSystem.OSProductSuite
    Wscript.Echo "OS Type: " & objOperatingSystem.OSType
    Wscript.Echo "Primary: " & objOperatingSystem.Primary
    Wscript.Echo "Registered User: " & objOperatingSystem.RegisteredUser
    Wscript.Echo "Serial Number: " & objOperatingSystem.SerialNumber
    Wscript.Echo "Version: " & objOperatingSystem.Version
Next

Others you can use , for example to get Bios information is Win32_Bios, Win32_PhysicalMemory, Win32_PhysicalMemoryArray for memory info, etc . Please research MSDN vbscript or simple google the various WMI you can use to get computer hardware information.

ghostdog74
+1  A: 

This is the script i ended up with. I thank ghost greatly because he pointed me in a great direction. I am someone that does not do scripting at all but I was able to figure it out.

The code post function is mangling this mangled mess even more but it is working so I am happy.

On Error Resume Next
Set dtmConvertedDate = CreateObject("WbemScripting.SWbemDateTime")    
strComputer = "."
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")    
Set colOperatingSystems = objWMIService.ExecQuery("Select * from Win32_OperatingSystem")
Set colComputerSystems = objWMIService.ExecQuery("Select * from Win32_ComputerSystem")
Const ForAppending = 2
Set objFSO = CreateObject("Scripting.FileSystemObject")
     For Each objComputerSystem in colComputerSystems
      dim txtfilename
      txtfilenamepc = objComputerSystem.Name
     dim longuser
     longuser = objComputerSystem.UserName
     dim myArray
     MyArray = Split(longuser,"\")
     dim shortuser
       if MyArray(2) = "" then shortuser = MyArray(1) else shortuser = MyArray(2)
    next
Set objTextFile = objFSO.OpenTextFile _
    ("\\hqfs01\TSUInstall\tools\damir\pcinfologs\" & shortuser & "-" & txtfilenamepc & ".txt", ForAppending, True)
For Each objComputerSystem in colComputerSystems

    objTextFile.WriteLine "User Name: " & shortuser
    objTextFile.WriteLine "Computer Name: " & objComputerSystem.Name
    objTextFile.WriteLine "Model: " & objComputerSystem.Model

    dim ramraw, ramdivider
    ramdivider = 1048576
    ramraw = objComputerSystem.TotalPhysicalMemory
    objTextFile.WriteLine "RAM: " & ramraw\ramdivider & " MB"
    Next
For Each objOperatingSystem in colOperatingSystems
    objTextFile.WriteLine "Operating System: " & objOperatingSystem.Caption
    objTextFile.WriteLine "Service Pack: " & objOperatingSystem.ServicePackMajorVersion
    Next
objTextFile.Close
Damir
A: 

The problem you have is that findstr handles spaces in the search string a little different:

Use spaces to separate multiple search strings unless the argument is prefixed with /C. For example, 'FINDSTR "hello there" x.y' searches for "hello" or "there" in file x.y. 'FINDSTR /C:"hello there" x.y' searches for "hello there" in file x.y.

So your long chain of findstrs would ignore every line that contain even a single work from any one search string. You can prefix the search strings with /C to avoid that:

type *.txt | findstr /v /c:"OS Manufacturer:" | findstr /v /c:"OS Configuration:" | ...

Also a problem is that the search strings may appear anywhere in the line with above syntax. You can anchor them to the start of the line by using regular expressions:

type *.txt | findstr /r /v /c:"^OS Manufacturer:" | findstr /r /v /c:"^OS Configuration:" | ...

The ^ acts as anchor and tells findstr to match this only at the start of a line. But when using regex you have to escape some characters, such as a dot.

Joey