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

Home Forums Scripting General Scripting Script to extract the last word in the last line of a text file

This topic contains 0 replies, has 1 voice, and was last updated by  chrispage 9 months, 4 weeks ago.

Viewing 1 post (of 1 total)
  • Author
    Posts

  • chrispage
    Member
    #167420

    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

    [SIZE=14px]autohotkey.ahk[/SIZE]
    NumpadSub::
    IfWinExist “ahk_class LyncTabFrameHostWindowClass”
    WinActivate
    WinGetActiveTitle, Title
    Run C:Scriptswww2.bat %Title%
    Return
    Return[/CODE]

    [B][SIZE=14px]www2.bat[/SIZE][/B]
    [CODE]@echo off
    findstr /i %1 x:itlogswho_when.txt | findstr /i %2
    Pause
    [/CODE]

    [I]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..[/I]

    [SIZE=14px][B]who_when.txt[/B]
    [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[/CODE]

    I hope this all makes sense.. [/SIZE]
    [CODE]NumpadSub::
    IfWinExist “ahk_class LyncTabFrameHostWindowClass”
    WinActivate
    WinGetActiveTitle, Title
    Run C:Scriptswww2.bat %Title%
    Return
    Return[/CODE]

    [SIZE=14px]www2.bat[/SIZE]
    @echo off
    findstr /i %1 x:itlogswho_when.txt | findstr /i %2
    Pause
    [/CODE]

    [I]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..[/I]

    [SIZE=14px][B]who_when.txt[/B]
    [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[/CODE]

    I hope this all makes sense.. [/SIZE]
    [CODE]@echo off
    findstr /i %1 x:itlogswho_when.txt | findstr /i %2
    Pause
    [/CODE]

    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..

    [SIZE=14px]who_when.txt
    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[/CODE]

    I hope this all makes sense.. [/SIZE]
    [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[/CODE]

    I hope this all makes sense.. [/SIZE]

Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.