What does the following piece of cmd code means? [closed] - batch-file

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 1 year ago.
Improve this question
What does this piece of code means? Could someone explain it to me?
set "txt=!txt:~0,-1!"
#echo off
setlocal EnableDelayedExpansion
set "txt="
set input=input.txt
for /f "delims=" %%a in (%input%) do (
set "txt=!txt!%%a,"
)
set "txt=!txt:~0,-1!"
>new.txt echo !txt!

This code returns a substring of the contents of the variable txt.
The two numbers indicate the start and end location of the requested substring in the original value of variable txt.
A negative value for the second number means count backwards.
So in your example the returned value will be the contents of variable txt without the last character.
For more info on this syntax see:
https://ss64.com/nt/syntax-substring.html

It does mean: 'cut last character from variable !txt!'

Related

I need to extract a line from the text with batch for ngrok link [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 8 months ago.
Improve this question
I need to generate a ngrok link and show only the link with batch.
I have downloaded the web "localhost/4040/api/tunnels". I think of getting the page source. But I got this:
{"tunnels":[{"name":"command_line","ID":"7769cea7b2843d7ded705c62afde8dd3","uri":"/api/tunnels/command_line","public_url":"https://32a6-203-89-122-249.ap.ngrok.io","proto":"https","config":{"addr":"http://localhost:4040","inspect":true},"metrics":{"conns":{"count":0,"gauge":0,"rate1":0,"rate5":0,"rate15":0,"p50":0,"p90":0,"p95":0,"p99":0},"http":{"count":0,"rate1":0,"rate5":0,"rate15":0,"p50":0,"p90":0,"p95":0,"p99":0}}}],"uri":"/api/tunnels"}
Now I need to extract the public_url and the link. What can I do to extract it? The link can be different.
#ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION
SET "line={"tunnels":[{"name":"command_line","ID":"7769cea7b2843d7ded705c62afde8dd3","uri":"/api/tunnels/command_line","public_url":"https://32a6-203-89-122-249.ap.ngrok.io","proto":"https","config":{"addr":"http://localhost:4040","inspect":true},"metrics":{"conns":{"count":0,"gauge":0,"rate1":0,"rate5":0,"rate15":0,"p50":0,"p90":0,"p95":0,"p99":0},"http":{"count":0,"rate1":0,"rate5":0,"rate15":0,"p50":0,"p90":0,"p95":0,"p99":0}}}],"uri":"/api/tunnels"}"
SET "line=%line:[=%"
SET "line=%line:{=%"
SET "line=%line:]=%"
SET "line=%line:}=%"
SET "line=%line:":"=","%"
SET "line=%line:":=",%"
SET "public_url=undefined"
SET "assign_next="
FOR %%e IN (%line%) DO (
ECHO %%e
IF DEFINED assign_next SET "!assign_next!=%%~e"
IF DEFINED %%~e (SET "assign_next=%%~e") ELSE (SET "assign_next=")
)
ECHO ------------------------
SET public_url
GOTO :EOF
No idea where the data line you've used as an example is stored, so I've assumed it's in an environment variable line.
As for what you mean by the link - you could have specified which field you mean, or perhaps you mean the link specified as the data item public_url.
So - assuming your data is in line, use string-replace to delete {, [, etc. by replacing by nothing, then each ":" by "," and follow the bouncing ball...
Set the name(s) of the field(s) required to undefined (just a meaningful string, nothing magic) and process line with a simple for loop as a sequence of possibly-quoted tokens separated by commas.
The echo %%e command is simply for show to allow the token being evaluated to be seen.
assign_next is "set" to nothing before the for loop, so it will start as not defined
If a token matches a defined variable, then the next token contains the desired data, so set assign_next to the name of the variable to which to assign the next token.
If assign_next is defined, then assign the current token to the variablename contained in assign_next.
... and display results using set.

I don't know how to do random numbers [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 1 year ago.
Improve this question
here's the story
so I want to create a batch file that can record attendance
so here's my problem- how can I enter random numbers on my batch file?
wait here's another problem: what I going to do to save the random number entered on the batch file to a folder like this-
MD [random number]
i'm not quite sure if this is what you mean but I think I have an idea;
In order to create a random number in batch you want to use "%random%", without the quotes of course.
This will generate a random number from 0 to 32767.
If you want to set this number to a variable you want to do:
set /a var=%random%
So for example you would have:
:createFolder (
set /a var=%random%
md %var%
)
If you need anymore help, feel free to contact me, or you can send me a message on Fiverr if you need me to write you up a program :)

Search for the first show of a expression in text file and copy it to the clipboard -using cmd [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 2 years ago.
Improve this question
I want to create a bat file that will search for a specific expression in a text file and copy it to my clipboard,
Example:
I want to search in this file C:\test.log The first instance of:
TestSerialNumber = %%%%%%%%%
(The %%%%%%%% are 8 numbers, for example: TestSerialNumber = 44436643, the numbers change)
And copy only the numbers to the clipboard
I got entangled with finding the first show.
I would appreciate help
This should work:
for /f "tokens=2 delims== " %%a in ('findstr TestSerialNumber c:\test.log') do echo %%a | clip

Reading a txt line by line in a batch file [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Improve this question
I am driving myself crasy trying to read this txt file in a batch file:
Binary CapabilityDescriptions Caption Availability
TRUE Intel(R) Active Management Technology - SOL (COM3) 2
TRUE Intel(R) Active Management Technology - SOL (COM4) 2
TRUE Intel(R) Active Management Technology - SOL (COM5) 2
I am trying to get the the COM number if the Caption contains the string "Intel".
Try this:
#echo off
setlocal
for /f "tokens=4 delims=()" %%a in ('findstr "Intel(R)" findintel.txt') do echo %%a

Batch programming - some questions [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I have a problem with understanding a batch file that is a part of a task (sort of hackme).
I find it hard to find informations about it in google, i dont know, i feel like there isnt any good batch language documentation or soemthing other that is solid.
my first question, what it does? It is possible to dont satisfy the condition ?
if not "!"=="" (
echo Authorization failed!
pause>nul
exit
)
Secound question, what this kind of IF's does ?:
set %1.pass=%2
if "!%1.pass:~5,1!"=="" (
.....
if not "!%1.pass:~6,1!"=="" (
Thank you,
#EDIT
technet.microsoft.com/en-us/library/cc754340(v=ws.10).aspx
i have read it, it doesnt answer my questions
You might check it out by yourself:
#echo off &SETLOCAL
if not "!"=="" (ECHO NOT equal) ELSE ECHO equal
SETLOCAL ENABLEDELAYEDEXPANSION
if not "!"=="" (ECHO NOT equal) ELSE ECHO equal
SET "property.pass=ABCDE"
ECHO %property.pass:~0,1% %property.pass:~1,1% %property.pass:~2,1% %property.pass:~3,1%
Output is:
NOT equal
equal
A B C D

Resources