Page 1 of 1
Find string in a big txt file and rturn the number line where the string is
Posted: 03 May 2019 03:37
by sal21
i'm working with vb6.
possible to:
Find a string in a big txt file and return the number of line where the string is found?
Naturally store the line number in a variable
note:
i need to integrate the batch in my vb6 application
tks and sorry for my bad english.
Re: Find string in a big txt file and rturn the number line where the string is
Posted: 03 May 2019 03:47
by aGerman
Code: Select all
for /f "delims=:" %%i in ('findstr /nc:"your string" "your file.txt"') do set "n=%%i"
... untested though.
i need to integrate the batch in my vb6 application
Any good reason why you don't do this task in VB directly?
Steffen
Re: Find string in a big txt file and rturn the number line where the string is
Posted: 05 May 2019 10:40
by sal21
tks!
Sorry for delay.
but i need to use vb6.
possible to use the VB6 Shell?
If yes, have an idea for vb6 code?
Tks
Re: Find string in a big txt file and rturn the number line where the string is
Posted: 05 May 2019 10:43
by sal21
aGerman wrote: ↑03 May 2019 03:47
Code: Select all
for /f "delims=:" %%i in ('findstr /nc:"your string" "your file.txt"') do set "n=%%i"
... untested though.
i need to integrate the batch in my vb6 application
Any good reason why you don't do this task in VB directly?
Steffen
tks!
Sorry for delay.
but i need to use vb6.
possible to use the VB6 Shell?
If yes, have an idea for vb6 code?
Tks
Re: Find string in a big txt file and rturn the number line where the string is
Posted: 05 May 2019 10:49
by aGerman
but i need to use vb6.
I'm not experienced with VB6. This is a Batch forum and I offered a Batch solution...
Steffen
Re: Find string in a big txt file and rturn the number line where the string is
Posted: 05 May 2019 11:20
by sal21
aGerman wrote: ↑05 May 2019 10:49
but i need to use vb6.
I'm not experienced with VB6. This is a Batch forum and I offered a Batch solution...
Steffen
ok
i can trap your code in a file .bat?
In this case i know the code in vb6 to lunch the bat.
if is possible, can you integrate your code to return the number of line finded in c:\test\myresult.txt
tks
Re: Find string in a big txt file and rturn the number line where the string is
Posted: 06 May 2019 11:07
by aGerman
Just a guess ...
Code: Select all
@for /f "delims=:" %%i in ('findstr /nc:"your string" "your file.txt"') do exit /b %%i
No idea if that is what "return the number" means in your case.
Steffen
Re: Find string in a big txt file and rturn the number line where the string is
Posted: 07 May 2019 00:54
by sal21
aGerman wrote: ↑06 May 2019 11:07
Just a guess ...
Code: Select all
@for /f "delims=:" %%i in ('findstr /nc:"your string" "your file.txt"') do exit /b %%i
No idea if that is what "return the number" means in your case.
Steffen
HI Steffen, TKS FOR CODE.!
To save the result of bat in c:\testdir\result.txt, in this case the number of line found?
is this correct:
@for /f "delims=:" %%i in ('findstr /nc:"your string" "your file.txt"') do exit /b %%i > c:\testdir\result.txt
Re: Find string in a big txt file and rturn the number line where the string is
Posted: 07 May 2019 06:16
by aGerman
No, you have to redirect the ECHO output to the file.
Code: Select all
@for /f "delims=:" %%i in ('findstr /nc:"your string" "your file.txt"') do >"c:\testdir\result.txt" echo %%i
Steffen
Re: Find string in a big txt file and rturn the number line where the string is
Posted: 07 May 2019 06:35
by sal21
aGerman wrote: ↑07 May 2019 06:16
No, you have to redirect the ECHO output to the file.
Code: Select all
@for /f "delims=:" %%i in ('findstr /nc:"your string" "your file.txt"') do >"c:\testdir\result.txt" echo %%i
Steffen
Is this correct?
Re: Find string in a big txt file and rturn the number line where the string is
Posted: 07 May 2019 06:41
by aGerman
Does it work?
How should I know the content of your 985.txt and if all paths are correct and existing?
Steffen
Re: Find string in a big txt file and rturn the number line where the string is
Posted: 07 May 2019 06:50
by sal21
aGerman wrote: ↑07 May 2019 06:41
Does it work?
How should I know the content of your 985.txt and if all paths are correct and existing?
Steffen
resolved!
wRONG PATH!
tHE CODE NOW WORK PERFECT!
Bro, love Pizza?
When you come in Napoli....
Tks also for your time.
Sal
Re: Find string in a big txt file and rturn the number line where the string is
Posted: 09 May 2019 06:52
by sal21
aGerman wrote: ↑07 May 2019 06:41
Does it work?
How should I know the content of your 985.txt and if all paths are correct and existing?
Steffen
OPS.....
in txt file i can have:
AAAA
AAAA
AAAA
The bat capture all AAAA...
in my work i need to capture only the first occurrence of AAAA, and exit from the code, possible?
Re: Find string in a big txt file and rturn the number line where the string is
Posted: 09 May 2019 08:13
by aGerman
Try it this way
Code: Select all
@for /f "delims=:" %%i in ('findstr /nc:"your string" "your file.txt"') do >"c:\testdir\result.txt" echo %%i&exit /b
Steffen