Announcement

Collapse
No announcement yet.

Script to extract the last word in the last line of a text file

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Script to extract the last word in the last line of a text file

    Hello smart people

    This has got me stumped and is outside my wheelhouse..
    Here is what i want to do..

    * lift the name of the person i am talking to in Skype for Business
    * Search for that name in a text file which logs user logins across the network
    * Extract the last word (the computer name) from the last line (the most recent entry) from a static text file
    * Run SCCM Remote Control %computername%

    Currently the process that our service desk goes through to extract the computer name and then connect to their computer is frankly embarrassing - but more importantly its super time consuming..

    This is how far i have gotten..

    I use autohotkey so bind the Numpad Subtract key to lift the persons name and then give it to the www2.bat file.

    The part i am stuck on is the last part.. filtering out all but the most recent entry and only the last word which is

    autohotkey.ahk
    Code:
    NumpadSub::
      IfWinExist "ahk_class LyncTabFrameHostWindowClass"
        WinActivate  
        WinGetActiveTitle, Title
        Run C:\Scripts\www2.bat %Title%
        Return
    Return
    www2.bat
    Code:
    @echo off
    findstr /i %1 x:\itlogs\who_when.txt | findstr /i %2
    Pause
    So i can filter the huge who_when.txt down to just the user I am currently talking to and the machine they are using..

    I only need the last word from the last line..




    who_when.txt
    Code:
    24/11/2017 11:24:23     SmithS         Steve Smith                     B0K9VY1
    27/11/2017 12:09:00     SmithS         Steve Smith                     B0K9VY1
    29/11/2017 07:07:26     SmithS         Steve Smith                     B0K9VY1
    01/12/2017 07:14:24     SmithS         Steve Smith                     B0K9VY1
    04/12/2017 07:00:52     SmithS         Steve Smith                     B0K9VY1
    06/12/2017 07:06:00     SmithS         Steve Smith                     B0K9VY1
    11/12/2017 07:10:16     SmithS         Steve Smith                     B0K9VY1
    13/12/2017 11:26:24     SmithS         Steve Smith                     B0K9VY1
    18/12/2017 07:21:39     SmithS         Steve Smith                     B0K9VY1
    22/12/2017 14:58:30     SmithS         Steve Smith                     B0K9VY1
    08/01/2018 07:26:37     SmithS         Steve Smith                     B0K9VY1
    15/01/2018 07:25:33     SmithS         Steve Smith                     B0K9VY1
    17/01/2018 07:15:21     SmithS         Steve Smith                     B0K9VY1
    19/01/2018 08:19:41     SmithS         Steve Smith                     B0K9VY1
    22/01/2018 06:52:44     SmithS         Steve Smith                     B0K9VY1
    23/01/2018 07:38:08     SmithS         Steve Smith                     B0K9VY1
    25/01/2018 13:10:14     SmithS         Steve Smith                     B0K9VY1
    29/01/2018 07:07:31     SmithS         Steve Smith                     B0K9VY1
    01/02/2018 07:28:13     SmithS         Steve Smith                     B0K9VY1
    08/02/2018 08:00:20     SmithS         Steve Smith                     B0K9VY1
    12/02/2018 07:52:49     SmithS         Steve Smith                     B0K9VY1
    12/02/2018 10:17:58     SmithS         Steve Smith                     B0K9VY1
    13/02/2018 09:29:13     SmithS         Steve Smith                     B0K9VY1
    13/02/2018 11:15:00     SmithS         Steve Smith                     B0K9VY1
    I hope this all makes sense..

Working...
X