New
#11
Yep I got it a bit better now but it still dosn't get all the variables on some batch that I tested...
Yep I got it a bit better now but it still dosn't get all the variables on some batch that I tested...
Test this one it's better than the one I made before but still not perfect, get's up to 7 variables on each line. If you see Wolfsblut in the end the batch made it to the end and did not get broken somewhere...
Code:@echo off chcp 1252 > Nul if exist "%~1" set "File=%~1" set Result=%~n1_Variables.txt if exist "%Result%" del /q "%Result%" echo/|set /p=Normal : >>"%Result%" set VT=N for /f "delims=" %%a in ('type "%File%" ^|findstr /i "%%.*%%"') do for /f tokens^=2^,^3^,^4^,^5^,^6^,^7^,^8^,^9^,^10^,^11^,^12^,^13^,^14^,^15^,^16^ delims^=%% %%b in ("%%a") do call :Normal "%%b" "%%c" "%%d" "%%e" "%%f" "%%g" "%%h" "%%i" "%%j" "%%k" "%%l" "%%m" "%%n" "%%o" "%%p" echo.>>"%Result%" echo/|set /p=Delayed Expansion: >>"%Result%" set VT=E for /f "delims=" %%a in ('type "%File%" ^|findstr /i "!.*!"') do for /f tokens^=2^,^3^,^4^,^5^,^6^,^7^,^8^,^9^,^10^,^11^,^12^,^13^,^14^,^15^,^16^ delims^=! %%b in ("%%a") do Call :Normal "%%b" "%%c" "%%d" "%%e" "%%f" "%%g" "%%h" "%%i" "%%j" "%%k" "%%l" "%%m" "%%n" "%%o" "%%p" echo Wolfsblut pause exit :Normal set "Var=%~1" set Contador=0 :Repeat set /a Repe+=1 IF not "%~1"==" " IF not "%~1"=="" ( set /a Contador+=1 call :FindVar%VT% "%~1" ) shift If not %Repe% GEQ 14 goto :Repeat goto :EOF pause :FindVarN echo "%~1" |findstr "\\ / ~ @ ( ) : \ & | - dp0 dpnx" 1> nul 2>nul || find "%~1" "%Result%" 1> nul 2> nul || echo/ |set /p=%%%~1%% >> "%Result%" goto :EOF :FindVarE echo "%~1" |findstr "\\ / ~ @ ( ) : \ & | - dp0 dpnx" 1> nul 2>nul|| find "%~1" "%Result%" 1> nul 2> nul || echo/ |set /p=!%~1! >> "%Result%" goto :EOF
Hello @ricardobohner,
Thank you, but unfortunately, it only produced the following . . .
Code:Normal : %Title% %Author% Sets the default console foreground and background colors. COLOR [attr] attr Specifies color attribute of console output Color attributes are specified by TWO hex digits -- the first corresponds to the background; the second the foreground. Each digit can be any of the following values: 0 = Black 8 = Gray 1 = Blue 9 = Light Blue 2 = Green A = Light Green 3 = Aqua B = Light Aqua 4 = Red C = Light Red 5 = Purple D = Light Purple 6 = Yellow E = Light Yellow 7 = White F = Bright White If no argument is given, this command restores the color to what it was when CMD.EXE started. This value either comes from the current console window, the /T command line switch or from the DefaultColor registry value. The COLOR command sets ERRORLEVEL to 1 if an attempt is made to execute the COLOR command with a foreground and background color that are the same. Example: "COLOR fc" produces light red on bright white
. . . which is the first TWO variable on the first line that hadVariables
.
Hello @ricardobohner,
I have been trying to achieve this usingPowerShell
[ I have spent hours on it ] as you are having a go usingBatch
. I doNOT
know PowerShell, but I thought I would have a go along with my friend Google. Unfortunately, I amNOT
having much success [ had some though ] with it, YET.
UPDATE:
I have cracked it usingPowerShell
, although a brute force approach . . .
Code:$Source_File = Get-Content 'C:\Users\System-Admin\Desktop\System_Reports.bat' $Destination_File = 'C:\Users\System-Admin\Desktop\AAA.txt' if (Test-Path $Destination_File) { Remove-Item $Destination_File } ForEach ($Line In $Source_File) { If ($Line -Like "%??%") { $Line | Out-File -FilePath $Destination_File -Append } } ForEach ($Line In $Source_File) { If ($Line -Like "%???%") { $Line | Out-File -FilePath $Destination_File -Append } } ForEach ($Line In $Source_File) { If ($Line -Like "%????%") { $Line | Out-File -FilePath $Destination_File -Append } } ForEach ($Line In $Source_File) { If ($Line -Like "%????%") { $Line | Out-File -FilePath $Destination_File -Append } } ForEach ($Line In $Source_File) { If ($Line -Like "%?????%") { $Line | Out-File -FilePath $Destination_File -Append } } ForEach ($Line In $Source_File) { If ($Line -Like "%??????%") { $Line | Out-File -FilePath $Destination_File -Append } } ForEach ($Line In $Source_File) { If ($Line -Like "%???????%") { $Line | Out-File -FilePath $Destination_File -Append } } ForEach ($Line In $Source_File) { If ($Line -Like "%????????%") { $Line | Out-File -FilePath $Destination_File -Append } } ForEach ($Line In $Source_File) { If ($Line -Like "%?????????%") { $Line | Out-File -FilePath $Destination_File -Append } } ForEach ($Line In $Source_File) { If ($Line -Like "%??????????%") { $Line | Out-File -FilePath $Destination_File -Append } } ForEach ($Line In $Source_File) { If ($Line -Like "%???????????%") { $Line | Out-File -FilePath $Destination_File -Append } } ForEach ($Line In $Source_File) { If ($Line -Like "%????????????%") { $Line | Out-File -FilePath $Destination_File -Append } } ForEach ($Line In $Source_File) { If ($Line -Like "%?????????????%") { $Line | Out-File -FilePath $Destination_File -Append } } ForEach ($Line In $Source_File) { If ($Line -Like "%??????????????%") { $Line | Out-File -FilePath $Destination_File -Append } } ForEach ($Line In $Source_File) { If ($Line -Like "%???????????????%") { $Line | Out-File -FilePath $Destination_File -Append } } ForEach ($Line In $Source_File) { If ($Line -Like "%????????????????%") { $Line | Out-File -FilePath $Destination_File -Append } } ForEach ($Line In $Source_File) { If ($Line -Like "%????????????????%") { $Line | Out-File -FilePath $Destination_File -Append } } ForEach ($Line In $Source_File) { If ($Line -Like "%?????????????????%") { $Line | Out-File -FilePath $Destination_File -Append } } ForEach ($Line In $Source_File) { If ($Line -Like "%??????????????????%") { $Line | Out-File -FilePath $Destination_File -Append } } ForEach ($Line In $Source_File) { If ($Line -Like "%???????????????????%") { $Line | Out-File -FilePath $Destination_File -Append } } $Source_File = "C:\Users\System-Admin\Desktop\AAA.txt" $Destination_File = 'C:\Users\System-Admin\Desktop\BBB.txt' if (Test-Path $Destination_File) { Remove-Item $Destination_File } $Unique_Values = $( ForEach ($Line in Get-Content $Source_File) { $Line.Split(" ") }) | Sort-Object | Get-Unique $Unique_Values | Out-File $Destination_File -Append $Unique_Values.Count | Out-File $Destination_File -Append
- It EXTRACTS ALL the
Variables
ONLY intoAAA.txt
.- It then SORTS that file ALPHABETICALLY and creates
BBB.txt
which also includes theTotal Unique Variables
.
I will spend some time tidying up the code tomorrow if I get time.
Cool, happy you made it. What do you need the variables of the batch file for?
Hello @ricardobohner,
First of all, THANK YOU for your time and effort on trying to resolve this, it is appreciated.
It is mainly for restructuring theVariables
if needed. I have already written the Script for that and tested it anyway.
Thanks again.
Not sure exactly the format you have - but suggest using regex to get string patterns
https://docs.microsoft.com/en-us/pow...powershell-7.1
Paul, this is a simple PS script to get all variables within two % signs, provided they contain no spaces or other symbols; this is just to see if others can try and make it more viable for your use case.
The Regex pattern should capture patterns only for upto 18 alphanumeric characters as in your post, such asCode:$Sourcefile = 'C:\test2\testfile.txt' $findthis='\%~{0,1}\w{1,18}~{0,1}\%' $findalso='\!~{0,1}\w{1,18}~{0,1}\!' Select-String -Path $Sourcefile -Pattern $findthis -AllMatches | % { $_.Matches } | % { $_.Value } | Sort | Unique | Out-file -FilePath 'C:\test2\RESULTtestfile.txt' Select-String -Path $Sourcefile -Pattern $findalso -AllMatches | % { $_.Matches } | % { $_.Value } | Sort | Unique | Out-file -FilePath 'C:\test2\RESULTtestfile.txt' -Append
%abc%
%~1abc%
%123456789012345678%
!~2a!
etc
Hopefully more knowledgeable members may refine it.