parsing command output RRS feed

  • Question

  • Hi,

    I am running a command (snmpwalk) where I want the output to be exported in a fixed format to a file.

    snmpget -c test
    Current output: : OCTET STRING- (ascii): 135af92add8cb1bac443e8582775dc41

    I need to output to display as below when I write this to a file:


    Is it possible to extract only the version info using the batch command and display the output as shown?

    It will always be the 5th field on the Current output

    So I am hoping something like this 

    snmpget -c test >> Out-File version=&5


    Thursday, May 18, 2017 4:33 PM

All replies

  • This is not a bath forum.  It is for PowerShell.

    With PowerShell we can usually parse any string output.

    ' : OCTET STRING- (ascii): 135af92add8cb1bac443e8582775dc41' -match '\(ascii\)\:\s+(.*)'
    $$version = matches[1]

    The next thing to do is learn PowerShell.


    Thursday, May 18, 2017 4:47 PM
  • Hi,

    I am using the replace string to update a list of files. The script runs however it does not update the string as expected. There are no errors reported.

    Select-String -Path "D:\SCMTEMP\Harvest Lane Controller Update\Broward\Boca Raton\02\Lane Controller Assy\\" -Pattern " : OCTET STRING- (ascii): " | ForEach-Object {$_ -Replace " : OCTET STRING- (ascii): ", "version="}

    Current File : OCTET STRING- (ascii): 135af92add8cb1bac443e8582775dc41

    New File


    Any help will be greatly appreciated.


    • Merged by Bill_Stewart Friday, May 19, 2017 4:25 PM Duplicate
    Friday, May 19, 2017 4:10 PM
  • This is a DUPLICATE of you first post:

    I shoed you how to extract the version.  Why are you asking the same question but with more bad examples.


    Friday, May 19, 2017 4:21 PM
  • Sorry about that I I was able to use the correct cmdlet get-content to do what I was looking for.
    Friday, May 19, 2017 4:24 PM