Extract only numeric content without spaces
Moderator: DosItHelp
Extract only numeric content without spaces
Hello friends
I have a result in two var like this
Files: 134571
Directories: 3
Which I get with the help from the friend Squashman in this fórum with this expresión
dudir.exe -n -q |findstr /b /i "Files: Directories:" >file2.txt
or with
FOR /f "tokens=1*delims=:" %%G in ('findstr /n "^" D:\1G\GORIGEN.txt') do if %%G equ 1 SET jgGLINEA=%%H
This was very helpful, but now I need ONLY the numbers, without 0 or spaces on the left, result in the var %jgGLINEA%.
The numeric result content can have a variable values and diferent length.
I tryed with, for, find, tokens, and delims, but without a valid result.
Can some one help me in this new occasion ?
Thanks in advance for your time and knowledges.
Jorgegs from Spain
I have a result in two var like this
Files: 134571
Directories: 3
Which I get with the help from the friend Squashman in this fórum with this expresión
dudir.exe -n -q |findstr /b /i "Files: Directories:" >file2.txt
or with
FOR /f "tokens=1*delims=:" %%G in ('findstr /n "^" D:\1G\GORIGEN.txt') do if %%G equ 1 SET jgGLINEA=%%H
This was very helpful, but now I need ONLY the numbers, without 0 or spaces on the left, result in the var %jgGLINEA%.
The numeric result content can have a variable values and diferent length.
I tryed with, for, find, tokens, and delims, but without a valid result.
Can some one help me in this new occasion ?
Thanks in advance for your time and knowledges.
Jorgegs from Spain
Re: Extract only numeric content without spaces
Your question is not as clear as it could be, although it sounds simple.
The subject says you want numeric content, and your question says you do not want zeros - and your example doesn't show zeros.
Are you trying to get the number of files and directories in a subdirectory branch? or just one folder?
Dudir is not a default command...
The subject says you want numeric content, and your question says you do not want zeros - and your example doesn't show zeros.
Are you trying to get the number of files and directories in a subdirectory branch? or just one folder?
Dudir is not a default command...
Jorgegs wrote:I have a result in two var like thisCode: Select all
Files: 134571
Directories: 3
but now I need ONLY the numbers, without 0 or spaces on the left, result in the var %jgGLINEA%.
Re: Extract only numeric content without spaces
Thanks for your answer
Sorry for the examples
Dudir.exe is a renamed program by me, which gives me the var result using
FOR /f "tokens=1*delims=:" %%G in ('findstr /n "^" D:\1G\GORIGEN.txt') do if %%G equ 1 SET jgGLINEA=%%H
FOR /f "tokens=1*delims=:" %%G in ('findstr /n "^" D:\1G\GORIGEN.txt') do if %%G equ 2 SET jgGLINEB=%%H
FOR /f "tokens=1*delims=:" %%G in ('findstr /n "^" D:\1G\GORIGEN.txt') do if %%G equ 3 SET jgGLINEC=%%H
FOR /f "tokens=1*delims=:" %%G in ('findstr /n "^" D:\1G\GORIGEN.txt') do if %%G equ 4 SET jgGLINED=%%H
Result for the Files, the content of var jgGLINEA
Result for Directories, the content of var jgGLINEB
Result for Size, the content of var jgGLINEC
Result for Size on disk, the content of var jgGLINED
Files: 34589
Directories: 45
Size: 87.398 bytes
Size on disk: 87.456 bytes
This Works correctly.
But I need only the numbers without the names Files: or Directories: or Size or Size on Disk at the beginning of each line
and without spaces on the left side of the number,
and without the Word "bytes" at the end, in case of the two optios of Size. But OK with the ". for thousands".
The size of the var can have a different length.
This will means in the example, var A, B ,C and D, only
34589
45
87.398
87.456
In 4 different var. Each with every different result.
Excuse my old english
Thanks for your help
Jorgegs
Sorry for the examples
Dudir.exe is a renamed program by me, which gives me the var result using
FOR /f "tokens=1*delims=:" %%G in ('findstr /n "^" D:\1G\GORIGEN.txt') do if %%G equ 1 SET jgGLINEA=%%H
FOR /f "tokens=1*delims=:" %%G in ('findstr /n "^" D:\1G\GORIGEN.txt') do if %%G equ 2 SET jgGLINEB=%%H
FOR /f "tokens=1*delims=:" %%G in ('findstr /n "^" D:\1G\GORIGEN.txt') do if %%G equ 3 SET jgGLINEC=%%H
FOR /f "tokens=1*delims=:" %%G in ('findstr /n "^" D:\1G\GORIGEN.txt') do if %%G equ 4 SET jgGLINED=%%H
Result for the Files, the content of var jgGLINEA
Result for Directories, the content of var jgGLINEB
Result for Size, the content of var jgGLINEC
Result for Size on disk, the content of var jgGLINED
Files: 34589
Directories: 45
Size: 87.398 bytes
Size on disk: 87.456 bytes
This Works correctly.
But I need only the numbers without the names Files: or Directories: or Size or Size on Disk at the beginning of each line
and without spaces on the left side of the number,
and without the Word "bytes" at the end, in case of the two optios of Size. But OK with the ". for thousands".
The size of the var can have a different length.
This will means in the example, var A, B ,C and D, only
34589
45
87.398
87.456
In 4 different var. Each with every different result.
Excuse my old english
Thanks for your help
Jorgegs
Re: Extract only numeric content without spaces
This works here with your data in file.txt
Files: 34589
Directories: 45
Size: 87.398 bytes
Size on disk: 87.456 bytes
Code: Select all
@echo off
for /f "usebackq tokens=2 delims=:" %%a in ("file.txt") do for /f %%b in ("%%a") do echo %%b
Re: Extract only numeric content without spaces
Fantastic
Thanks for your answer to my problem.
The only question with this solution, is that I get the result all in one var
I need the result in 4 different var.
In any case thank you very much for your great helpfulness
Jorgegs
Thanks for your answer to my problem.
The only question with this solution, is that I get the result all in one var
I need the result in 4 different var.
In any case thank you very much for your great helpfulness
Jorgegs
Re: Extract only numeric content without spaces
This is a little bit of a kludge, but it works for your situation.
Code: Select all
@echo off
for /f "usebackq tokens=1,2 delims=:" %%a in ("file.txt") do for /f %%b in ("%%b") do set "var-%%a=%%b"
set "var-sizeondisk=%var-size on disk%"
set "var-size on disk="
set var-
pause & goto :EOF
Re: Extract only numeric content without spaces
Thank you "foxidrive".
I put you in a "DOS" monument
Now I get this result
var-Directories=26
var-Files=1037
var-Size=46.702.989
var-sizeondisk=46.702.989
But I need only the numbers as content for 4 separate var, without names and = symbol.
Because i need them to add the numbers in separate processes.
How can I do it ?
Thanks in advance for your time
Jorgegs
I put you in a "DOS" monument
Now I get this result
var-Directories=26
var-Files=1037
var-Size=46.702.989
var-sizeondisk=46.702.989
But I need only the numbers as content for 4 separate var, without names and = symbol.
Because i need them to add the numbers in separate processes.
How can I do it ?
Thanks in advance for your time
Jorgegs
-
- Posts: 128
- Joined: 23 May 2016 15:39
- Location: Spain
Re: Extract only numeric content without spaces
Jorge,
Foxidrive gives you a working solution. if you change set var- with echo %var-directories% %var-Files% %var-size% %var-sizeondisk%
Result is
Replace echo with the command you need.
BTW, if you want to avoid the dot in numbers...
Now, result is
Saludos!
foxidrive wrote:This is a little bit of a kludge, but it works for your situation.Code: Select all
@echo off
for /f "usebackq tokens=1,2 delims=:" %%a in ("file.txt") do for /f %%b in ("%%b") do set "var-%%a=%%b"
set "var-sizeondisk=%var-size on disk%"
set "var-size on disk="
set var-
pause & goto :EOF
Foxidrive gives you a working solution. if you change set var- with echo %var-directories% %var-Files% %var-size% %var-sizeondisk%
Code: Select all
@echo off
for /f "usebackq tokens=1,2 delims=:" %%a in ("file.txt") do for /f %%b in ("%%b") do set "var-%%a=%%b"
set "var-sizeondisk=%var-size on disk%"
set "var-size on disk="
echo %var-directories% %var-Files% %var-size% %var-sizeondisk%
pause & goto :EOF
Result is
45 34589 87.398 87.456
Replace echo with the command you need.
BTW, if you want to avoid the dot in numbers...
Code: Select all
@echo off
for /f "usebackq tokens=1,2 delims=:" %%a in ("file.txt") do for /f %%b in ("%%b") do set "var-%%a=%%b"
set "var-sizeondisk=%var-size on disk%"
set "var-size on disk="
set "var-size=%var-size:.=%"
set "var-sizeondisk=%var-sizeondisk:.=%"
echo %var-directories% %var-Files% %var-size% %var-sizeondisk%
pause & goto :EOF
Now, result is
45 34589 87398 87456
Saludos!
Re: Extract only numeric content without spaces
This is fantastic
Thanks for your help.
For me the command FOR is the understanded one.
It is very powerful and for me to complicated.
It is a pity that I do'nt know how to use it.
In any case, thanks, thanks, thanks.
Jorgegs
Thanks for your help.
For me the command FOR is the understanded one.
It is very powerful and for me to complicated.
It is a pity that I do'nt know how to use it.
In any case, thanks, thanks, thanks.
Jorgegs
Re: Extract only numeric content without spaces
Thanks for your followup, elzooilogico.
Jorgegs, unfortunately I didn't pay close attention and it looks more confusing than it should - because the second for command has %%b in three places instead of only one place - and it only works because a fluke of how batch code operates.
The second for command in that line should really be written like this
do for /f %%c in ("%%b") do set "var-%%a=%%c"
- where %%c is changing the text inside %%b and giving the result (in %%c).
I'm not surprised that it looks very odd the way it is written in my code.
Jorgegs wrote:For me the command FOR is the understanded one.
It is very powerful and for me to complicated.
Jorgegs, unfortunately I didn't pay close attention and it looks more confusing than it should - because the second for command has %%b in three places instead of only one place - and it only works because a fluke of how batch code operates.
The second for command in that line should really be written like this
do for /f %%c in ("%%b") do set "var-%%a=%%c"
- where %%c is changing the text inside %%b and giving the result (in %%c).
I'm not surprised that it looks very odd the way it is written in my code.
-
- Posts: 128
- Joined: 23 May 2016 15:39
- Location: Spain
Re: Extract only numeric content without spaces
foxidrive wrote:The second for command in that line should really be written like this
do for /f %%c in ("%%b") do set "var-%%a=%%c"
I can't believe I missed that Definitively I need more coffee in the morning!
-
- Posts: 75
- Joined: 01 Jun 2016 09:25
Re: Extract only numeric content without spaces
Jorgegs wrote:For me the command FOR is the understanded one.
It is very powerful and for me to complicated.
It is a pity that I do'nt know how to use it.
Here is a series of exercises I found very useful when learning about batch loops in general: http://resources.infosecinstitute.com/cmd-exe-loops-part-iii/
Rob van der Woude's excellent site also has a good overview of FOR loops specifically, along with some exercises:
- http://www.robvanderwoude.com/for.php
- http://www.robvanderwoude.com/variableexpansionexercise1.php
- http://www.robvanderwoude.com/variableexpansionexercise2.php
When all else fails, read the directions . The built-in documentation (for /? or help for) is actually pretty thorough, and always available.