none
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 100.115.128.102 1.3.6.1.4.1.25233.100.3.1.0
    Current output:

    1.3.6.1.4.1.25233.100.3.1.0 : OCTET STRING- (ascii): 135af92add8cb1bac443e8582775dc41

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

    version=135af92add8cb1bac443e8582775dc41

    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 100.115.128.102 1.3.6.1.4.1.25233.100.3.1.0 >> Out-File version=&5

    Thanks

    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.

    '1.3.6.1.4.1.25233.100.3.1.0 : 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\1.3.6.1.4.1.25233.100.3.1.0\oid_instance.properties" -Pattern "1.3.6.1.4.1.25233.100.3.1.0 : OCTET STRING- (ascii): " | ForEach-Object {$_ -Replace "1.3.6.1.4.1.25233.100.3.1.0 : OCTET STRING- (ascii): ", "version="}

    Current File

    1.3.6.1.4.1.25233.100.3.1.0 : OCTET STRING- (ascii): 135af92add8cb1bac443e8582775dc41

    New File

    version=135af92add8cb1bac443e8582775dc41

    Any help will be greatly appreciated.

    Thanks

    • 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: https://social.technet.microsoft.com/Forums/scriptcenter/en-US/59e9b72f-95ed-4246-9a4a-bbc6ffc1f49d/parsing-command-output?forum=ITCG#59e9b72f-95ed-4246-9a4a-bbc6ffc1f49d

    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