Find a string and set a line

  • This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.
Jan 9, 2015
9
0
#1
I need to find a string in a file (easy enough) and set the line that the string was found in as a variable.

set comp=%@word[0,%@line[list1.txt,%counter]]
set comp2=%@word[1,%@line[list1.txt,%counter]]
set comp3=%@instr[5,14,[2,%@line[list1.txt,%counter]]
set comp4=%@word[2,%@line[list1.txt,%counter]]
reg query %comp\HKU > tempkey.txt <this is the command and the file I need to search a string in.
S-1-5-21-1960230475-814316877 is the string in can search and find , but the line number moves from 5 to 7 depending on which pc I search on.
 
#2
Just a thought ...
Code:
v:\> type waittest.btm
alias hosts if exist v:\hosts (ren v:\hosts hosts.xxx) else (ren v:\hosts.xxx hosts)
hosts
start /wait firefox http://google.com
echo FireFox has closed
hosts
unalias hosts


v:\> echo %@strip[^[^],%@word[0,%@execstr[ffind /K /M /L /T"unalias" waittest.btm]]]
6

v:\> echo %@strip[^[^],%@word[0,%@execstr[ffind /K /M /L /T"closed" waittest.btm]]]
4
 
Likes: JB2
Jan 9, 2015
9
0
#3
Just a thought ...
Code:
v:\> type waittest.btm
alias hosts if exist v:\hosts (ren v:\hosts hosts.xxx) else (ren v:\hosts.xxx hosts)
hosts
start /wait firefox http://google.com
echo FireFox has closed
hosts
unalias hosts


v:\> echo %@strip[^[^],%@word[0,%@execstr[ffind /K /M /L /T"unalias" waittest.btm]]]
6

v:\> echo %@strip[^[^],%@word[0,%@execstr[ffind /K /M /L /T"closed" waittest.btm]]]
4
that looks promising going to try it .ty
 
Jan 9, 2015
9
0
#4
Just a thought ...
Code:
v:\> type waittest.btm
alias hosts if exist v:\hosts (ren v:\hosts hosts.xxx) else (ren v:\hosts.xxx hosts)
hosts
start /wait firefox http://google.com
echo FireFox has closed
hosts
unalias hosts


v:\> echo %@strip[^[^],%@word[0,%@execstr[ffind /K /M /L /T"unalias" waittest.btm]]]
6

v:\> echo %@strip[^[^],%@word[0,%@execstr[ffind /K /M /L /T"closed" waittest.btm]]]
4
it works and finds it and set the line number but it skips the first one it finds and selectects the second line
SET COMP5=%@strip[^[^],%@word[0,%@execstr[ffind /K /M /L /T"S-1-5-21-1960230475-814316877" TEMPKEY.TXT]]]


HKEY_USERS\.DEFAULT
HKEY_USERS\S-1-5-19
HKEY_USERS\S-1-5-19_Classes
HKEY_USERS\S-1-5-20
HKEY_USERS\S-1-5-20_Classes
HKEY_USERS\S-1-5-21-1960230475-814316877-1687796506-500 <line 6 it skips this one for some reason the above should find line 6 first?
HKEY_USERS\S-1-5-21-1960230475-814316877-1687796506-500_Classes <line 7
HKEY_USERS\S-1-5-18
 

samintz

Scott Mintz
May 20, 2008
1,203
11
Solon, OH, USA
#6
if you only need the output of REG QUERY to locate the line number you can pipe the output into FFIND instead of having to create a file first.
Code:
reg query HKU | ffind /klm /t"S-1-5-21-1960230475-814316877"

or to isolate the line number specifically:
set linenum=%@word["[]",0,%@execstr[reg query HKU | ffind /klm /t"S-1-5-21-1960230475-814316877"]
And FWIW, on my system I find the first match. I'm not sure how you are skipping it unless the file contents are not in the order you listed.
-Scott