Find Word After A String
Moderator: DosItHelp
Find Word After A String
Hi all,
I was wondering if it's possible to create a script to find a word at the end of a sentence or in the middle of a sentence that could be random.
The reason I'm trying to do this is because I have a logon script that writes when a user logs on and off through the %username% variable. I want to use Batch to select only the username after x (username) logged on at xx:xx (time), the reason I need something that finds the word before/after a sentence is because the logon script is randomised so the username isn't one per file.
Also, this would be helpful for so many other possible reasons.
Thanks in advance.
I was wondering if it's possible to create a script to find a word at the end of a sentence or in the middle of a sentence that could be random.
The reason I'm trying to do this is because I have a logon script that writes when a user logs on and off through the %username% variable. I want to use Batch to select only the username after x (username) logged on at xx:xx (time), the reason I need something that finds the word before/after a sentence is because the logon script is randomised so the username isn't one per file.
Also, this would be helpful for so many other possible reasons.
Thanks in advance.
Re: Find Word After A String
Can you give us an example of an entry?
Re: Find Word After A String
Sure, here's an example:
Logged off user1 at dd-mm-yy at xx:xx:xx (hours, minutes, seconds)
Logged on user2
Logged off user2
Logged on user3
In all the above examples the date and time is included.
Logged off user1 at dd-mm-yy at xx:xx:xx (hours, minutes, seconds)
Logged on user2
Logged off user2
Logged on user3
In all the above examples the date and time is included.
Re: Find Word After A String
GHamilton wrote:Sure, here's an example:
Logged off user1 at dd-mm-yy at xx:xx:xx (hours, minutes, seconds)
Logged on user2
Logged off user2
Logged on user3
In all the above examples the date and time is included.
From that sample, what do you want to extract?
Re: Find Word After A String
Sorry, I should clarify. What I want to do is get the last user logged onto a machine and add that to a text file and name it that username.
The layout of the logs on the server is just like that example that I included in my previous post.
The layout of the logs on the server is just like that example that I included in my previous post.
Re: Find Word After A String
So in the log above you want 'user3' - is that all?
You want one user per log file?
You want one user per log file?
Re: Find Word After A String
Essentially yes but I don't want to change the logon script, just split it later plus this could be used for other things.
What I really want is a script that will display the word which the user nay not know, after or before a sentence or phrase that they do know that would be in the script.
What I really want is a script that will display the word which the user nay not know, after or before a sentence or phrase that they do know that would be in the script.
Re: Find Word After A String
GHamilton wrote:Essentially yes but I don't want to change the logon script, just split it later plus this could be used for other things.
This batch file should get the last username
Code: Select all
@echo off
for /f "tokens=3" %%a in ('type "logfile.log" ^|findstr /i /c:"Logged on "') do set "user=%%a"
echo "%user%">"%user%.txt"
What I really want is a script that will display the word which the user nay not know, after or before a sentence or phrase that they do know that would be in the script.
You'll have to give an example of the text you want to search and also list the part you want to find.
Re: Find Word After A String
Thanks so much for that, I should be able to modify that for other uses.
Thanks so much for all your help, foxidrive.
Thanks so much for all your help, foxidrive.