I've been coding this script but I can't seem to get it to work.
What the code does:
- It counts the number of lines (%num%) of dfg.txt.
- Saves each line to a variable (%line(n)%(n being the number of the line))
- It finds the lines in database.enc and if they don't exist the script adds them like %line(n)%=%ran1%%ran2% to database.enc(%ran1% and %ran2% are generated by %random%, they are always unique because the batch also
- After all that it writes a new file (fileenc.txt) with the previously generated %ran1%%ran2% variables acording to each line from dfg.txt.
And as I said for some reason it isn't working.
Here's the code:
Code: Select all
@echo on &setlocal enableDelayedExpansion
set tempvar=temp
findstr /R /N "^" dfg.txt | find /C ":">totalyrandomwordthatnonewilleveruserandimeaneveryihopeyouhaventusedthis
< totalyrandomwordthatnonewilleveruserandimeaneveryihopeyouhaventusedthis set /p "num="
del totalyrandomwordthatnonewilleveruserandimeaneveryihopeyouhaventusedthis
for /f "tokens=2 delims=:" %%i in ('find /c /v "" dfg.txt') do (
for /l %%j in (1 1 %%i) do (
set /p "line%%j="
)
)<dfg.txt
set lines=1
:bb
if %tempvar%==pmet (
set /a lines=%lines%+1
)
set "tempvar=temp"
FINDSTR /C:"'!line%lines%!'" database.enc > nul
if errorlevel 1 (
set ran=%random%
set ran2=%random%
FINDSTR /C:"%ran%%ran2%" database.enc > nul
if errorlevel 1 (
echo '%line!lines!%'=%ran%%ran2%>>database.enc
echo %ran%%ran2%>>fileenc.txt
if %lines% gtr %num% (
set "tempvar=pmet"
goto bb
)
set action3=%action2%
set action2=%action1%
set "action1=Saved as fileenc.txt"
pause
) else (
goto bb
)
) else (
for /f "tokens=2 delims==" %%a in ('FINDSTR /C:"'%line!lines!%'" database.enc') do (
echo %%a>>fileenc.txt
if %lines% gtr %num% (
set "tempvar=pmet"
goto bb
)
set action3=%action2%
set action2=%action1%
set "action1=Saved as fileenc.txt"
)
pause
)
pause
Contents of dfg.txt:
Code: Select all
hello
test
test2
empty line4
The script isn't writing the apropriated lines, %line!lines!% should be %line(number)% which should be the content of a line but instead it's nothing, an empty variable.
Why is it an empty variable and what can I do to correct this ?
Thanks for reading and please help