Filtering Findstr results

Home Forums Scripting General Scripting Filtering Findstr results

This topic contains 1 reply, has 2 voices, and was last updated by  Rems 10 months ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts

  • chrispage
    Member
    #167424

    I am trying to extract the last word of a findstr results query

    The command I run
    findstr /i %1 x:itlogswho_when.txt | findstr /i %2[/CODE]
    the results I get
    [CODE]12/02/2018 10:17:58 SmithS Steve Smith B0K9VY1
    13/02/2018 09:29:13 SmithS Steve Smith B0K9VY1[/CODE]
    What i need from the results is that last word [I][B]B0K9VY1 [/B][/I]so i can run SCCM RemoteControl $computername

    (it will *always* be the last word on the last line of the results from my findstr query)[CODE]findstr /i %1 x:itlogswho_when.txt | findstr /i %2[/CODE]
    the results I get
    12/02/2018 10:17:58 SmithS Steve Smith B0K9VY1
    13/02/2018 09:29:13 SmithS Steve Smith B0K9VY1[/CODE]
    What i need from the results is that last word [I][B]B0K9VY1 [/B][/I]so i can run SCCM RemoteControl $computername

    (it will *always* be the last word on the last line of the results from my findstr query)[CODE]12/02/2018 10:17:58 SmithS Steve Smith B0K9VY1
    13/02/2018 09:29:13 SmithS Steve Smith B0K9VY1[/CODE]
    What i need from the results is that last word B0K9VY1 so i can run SCCM RemoteControl $computername

    (it will *always* be the last word on the last line of the results from my findstr query)


    Rems
    Moderator
    #228480

    For /F “tokens=*” %%a in (‘findstr /i %1 x:itlogswho_when.txt ^| findstr /i %2’) do for %%b in (%%a) do set machine=%%b
    SCCM RemoteControl %machine%[/CODE][CODE]For /F “tokens=*” %%a in (‘findstr /i %1 x:itlogswho_when.txt ^| findstr /i %2’) do for %%b in (%%a) do set machine=%%b
    SCCM RemoteControl %machine%[/CODE]

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.