search for previous item

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
AR Coding
Posts: 53
Joined: 02 May 2021 21:16

Re: search for previous item

#16 Post by AR Coding » 30 Jan 2022 20:21

Just curious... What is the %%I for?
Eureka! wrote:
30 Jan 2022 19:07

Code: Select all

for /f "usebackq tokens=1 delims=:" %%I in (`findstr.exe /n /i /c:"%search%" temp1.txt`) do call :GetArchive %%I <---
I dont see it getting used anywhere...

ShadowThief
Expert
Posts: 1166
Joined: 06 Sep 2013 21:28
Location: Virginia, United States

Re: search for previous item

#17 Post by ShadowThief » 30 Jan 2022 21:16

It gets referenced in :GetArchive as %1 and it tells the for loop in that subroutine how many lines to skip

darioit
Posts: 230
Joined: 02 Aug 2010 05:25

Re: search for previous item

#18 Post by darioit » 31 Jan 2022 04:45

Eureka! works fast and it's perfect for my purpose, thanks as always to all :D :D :D

darioit
Posts: 230
Joined: 02 Aug 2010 05:25

Re: search for previous item

#19 Post by darioit » 31 Jan 2022 07:02

I made a little improvement returning a full row find

Code: Select all

@echo off

set "file=report.txt"
set "search=%1"

findstr.exe /n /I /C:"#" /I /C:"%search%"  "%file%" | sort.exe /r /o temp1.txt

for /f "usebackq tokens=1 delims=:" %%I in (`findstr.exe /n /i /c:"%search%" temp1.txt`) do call :GetArchive %%I

del temp1.txt
goto :EOF

:GetArchive
(for /l %%i in (1,1,%1) do set /P "row=") < temp1.txt

for /f "usebackq  skip=%1  tokens=2 delims=#" %%X in (temp1.txt) do (
	echo %search% %%X %row%
	goto :EOF
)	

Eureka!
Posts: 137
Joined: 25 Jul 2019 18:25

Re: search for previous item

#20 Post by Eureka! » 31 Jan 2022 15:42

darioit wrote:
31 Jan 2022 04:45
Eureka! works fast and it's perfect for my purpose, thanks as always to all :D :D :D
You're welcome!

works fast
That makes me a bit curious: did you time this one too, @Squashman?

Post Reply