i m trying to compile batch file to search a string on a txt file and when it finds give the line number and place it to a variable so i can use it on a statement
example
name.txt
carolina
rita
sara
andre
in the example above i whant to find %username% = Andre and then return to a variable the number 4 if the %username% is not on the list i whant it to atribut the name "Hello" because the "andre" is in line 4
i found a code but icant adatp it to function
@echo off &setlocal
set "search=%username%"
set "replace=kordo anstataui"
set "textfile=name.txt"
set "newfile=new.txt"
(for /f "delims=" %%i in ('findstr /n "^" "%textfile%"') do (
set "line=%%i"
setlocal enabledelayedexpansion
set "line=!line:%search%=%replace%!"
echo(!line!
endlocal
))>"%newfile%"
type "%newfile%"
i hope it help the code helps
Ps:sorry for my bad writing