This website uses cookies. By clicking Accept, you consent to the use of cookies. Click Here to learn more about how we use cookies.
Turn on suggestions
Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.
- Revenera Community
- :
- InstallShield
- :
- InstallShield Forum
- :
- Re: Parsing string
Subscribe
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Subscribe
- Mute
- Printer Friendly Page
- Mark as New
- Subscribe
- Mute
- Permalink
- Report Inappropriate Content
Jul 21, 2017
09:39 AM
Parsing string
While executing the below code in cmd prompt :
systeminfo | findstr /C:”Total Physical Memory”
it returns the string
How can i get JUST 8072 ?
parsing Total Physical Memory: , the comma, spaces and MB?
Please help.
I am getting confused and failed multiple times by using strtrim, lists, strgettoken etc...
systeminfo | findstr /C:”Total Physical Memory”
it returns the string
“Total Physical Memory: 8,072 MB”
How can i get JUST 8072 ?
parsing Total Physical Memory: , the comma, spaces and MB?
Please help.
I am getting confused and failed multiple times by using strtrim, lists, strgettoken etc...
(15) Replies
- Mark as New
- Subscribe
- Mute
- Permalink
- Report Inappropriate Content
Jul 21, 2017
10:09 AM
One way to do it is to replace
With this
Note that this is a simple method that works if there is only 1 comma. If there is the possibility of multiple commas I would do it differently.
systeminfo | findstr /C:”Total Physical Memory”
With this
for /f "usebackq tokens=4-5 delims=:, " %%A in (`systeminfo ^| findstr /C:"Total Physical Memory"`) do echo(%%A%%B
Note that this is a simple method that works if there is only 1 comma. If there is the possibility of multiple commas I would do it differently.
- Mark as New
- Subscribe
- Mute
- Permalink
- Report Inappropriate Content
Jul 21, 2017
10:11 AM
rguggisberg wrote:
One way to do it is to replace
systeminfo | findstr /C:”Total Physical Memory”
With this
for /f "usebackq tokens=4-5 delims=:, " %%A in (`systeminfo ^| findstr /C:"Total Physical Memory"`) do echo(%%A%%B
Note that this is a simple method that works if there is only 1 comma. If there is the possibility of multiple commas I would do it differently.
Thanks, but in my case we need to handle multiple comma scenario. 😞
- Mark as New
- Subscribe
- Mute
- Permalink
- Report Inappropriate Content
Jul 21, 2017
10:20 AM
dinesh_redhawk wrote:
Thanks, but in my case we need to handle multiple comma scenario. 😞
OK... just gets a bit more complicated 🙂
setlocal enabledelayedexpansion & for /f "usebackq tokens=4-5 delims=: " %%A in (`systeminfo ^| findstr /C:"Total Physical Memory"`) do set "Memory=%%A" & set "Memory=!Memory:,=!" & ECHO(!Memory! & endlocal
- Mark as New
- Subscribe
- Mute
- Permalink
- Report Inappropriate Content
Jul 21, 2017
10:23 AM
rguggisberg wrote:
OK... just gets a bit more complicated 🙂
setlocal enabledelayedexpansion & for /f "usebackq tokens=4-5 delims=: " %%A in (`systeminfo ^| findstr /C:"Total Physical Memory"`) do set "Memory=%%A" & set "Memory=!Memory:,=!" & ECHO(!Memory! & endlocal
How to run this code? if i run it through CMD, its returning the following error:
%%A was unexpected at this time.
- Mark as New
- Subscribe
- Mute
- Permalink
- Report Inappropriate Content
Jul 21, 2017
10:28 AM
dinesh_redhawk wrote:
How to run this code? if i run it through CMD, its returning the following error:
%%A was unexpected at this time.
Ok, i tried running the command in Bat file and its giving the following output:
set "Memory=8,072" & set "Memory=!Memory:,=!" & ECHO(!Memory! & endlocal
8072
I need only 8072 to be written in a temp txt file, so that i can read it.
Appreciate your prompt help.
Thanks a lot.
- Mark as New
- Subscribe
- Mute
- Permalink
- Report Inappropriate Content
Jul 21, 2017
10:28 AM
dinesh_redhawk wrote:
How to run this code? if i run it through CMD, its returning the following error:
%%A was unexpected at this time.
If running via CMD you need to change BOTH %%A to %A
- Mark as New
- Subscribe
- Mute
- Permalink
- Report Inappropriate Content
Jul 21, 2017
10:34 AM
dinesh_redhawk wrote:
Ok, i tried running the command in Bat file and its giving the following output:
set "Memory=8,072" & set "Memory=!Memory:,=!" & ECHO(!Memory! & endlocal
8072
I need only 8072 to be written in a temp txt file, so that i can read it.
Appreciate your prompt help.
Thanks a lot.
Works in my bat file. Can you post yours? Sometimes that violates the security policy of this site 😞
We can write it to a file.but need to fix current problem first.
- Mark as New
- Subscribe
- Mute
- Permalink
- Report Inappropriate Content
Jul 21, 2017
10:38 AM
Change code to this
I will post code to write to file in a bit.
setlocal enabledelayedexpansion & for /f "usebackq tokens=4-5 delims=: " %%A in (`systeminfo ^| findstr /C:"Total Physical Memory"`) do set "Memory=%%A" & set "Memory=!Memory:,=!" & ECHO(!Memory! & endlocal
I will post code to write to file in a bit.
- Mark as New
- Subscribe
- Mute
- Permalink
- Report Inappropriate Content
Jul 21, 2017
10:40 AM
rguggisberg wrote:
Change code to this
setlocal enabledelayedexpansion & for /f "usebackq tokens=4-5 delims=: " %%A in (`systeminfo ^| findstr /C:"Total Physical Memory"`) do set "Memory=%%A" & set "Memory=!Memory:,=!" & ECHO(!Memory! & endlocal
I will post code to write to file in a bit.
This is also returning the following output 😞
set "Memory=8,072" & set "Memory=!Memory:,=!" & ECHO(!Memory! & endlocal
8072
- Mark as New
- Subscribe
- Mute
- Permalink
- Report Inappropriate Content
Jul 21, 2017
10:47 AM
dinesh_redhawk wrote:
This is also returning the following output 😞
set "Memory=8,072" & set "Memory=!Memory:,=!" & ECHO(!Memory! & endlocal
8072
Sorry 😞
Last code should have been
@echo off & setlocal enabledelayedexpansion & for /f "usebackq tokens=4-5 delims=: " %%A in (`systeminfo ^| findstr /C:"Total Physical Memory"`) do set "Memory=%%A" & set "Memory=!Memory:,=!" & ECHO(!Memory! & endlocal
Code to write to file is
@echo off & setlocal enabledelayedexpansion & for /f "usebackq tokens=4-5 delims=: " %%A in (`systeminfo ^| findstr /C:"Total Physical Memory"`) do set "Memory=%%A" & set "Memory=!Memory:,=!" & ECHO(!Memory! >"%Tempfile%" & endlocal
You need to replace %Tempfile% above with the path\filename of your desired file
- Mark as New
- Subscribe
- Mute
- Permalink
- Report Inappropriate Content
Jul 21, 2017
10:59 AM
rguggisberg wrote:
Sorry 😞
Last code should have been
@echo off & setlocal enabledelayedexpansion & for /f "usebackq tokens=4-5 delims=: " %%A in (`systeminfo ^| findstr /C:"Total Physical Memory"`) do set "Memory=%%A" & set "Memory=!Memory:,=!" & ECHO(!Memory! & endlocal
Code to write to file is
@echo off & setlocal enabledelayedexpansion & for /f "usebackq tokens=4-5 delims=: " %%A in (`systeminfo ^| findstr /C:"Total Physical Memory"`) do set "Memory=%%A" & set "Memory=!Memory:,=!" & ECHO(!Memory! >"%Tempfile%" & endlocal
You need to replace %Tempfile% above with the path\filename of your desired file
This worked... U are Amazing sir. I am very thankful to you for helping me so promptly.
One final question: Can the same be done for this command? wmic computersystem get TotalPhysicalMemory
Because the one we are using currently is taking some few seconds to return the result, while this command returns the result immediately. I know iam stretching it too much, but just wanted to know.
- Mark as New
- Subscribe
- Mute
- Permalink
- Report Inappropriate Content
Jul 21, 2017
11:24 AM
dinesh_redhawk wrote:
This worked... U are Amazing sir. I am very thankful to you for helping me so promptly.
One final question: Can the same be done for this command? wmic computersystem get TotalPhysicalMemory
Because the one we are using currently is taking some few seconds to return the result, while this command returns the result immediately. I know iam stretching it too much, but just wanted to know.
Depends. If you can live with the long number, yes.
@ECHO OFF & for /f %%A in ('wmic computersystem get TotalPhysicalMemory') do if not "%%A"=="TotalPhysicalMemory" echo(%%A >>"%Tempfile%"
Of course you need to replace %TempFile% above as needed.
Note that we have to use >> to append to the file. This is because wmic ouputs a LF or something at the end that the FOR loop does not interpret as an End Of Line... so we can't just re-write the file for each iteration of the loop. Because of this you will have to delete the temp file if it is present before you run this (good practice anyway).
- Mark as New
- Subscribe
- Mute
- Permalink
- Report Inappropriate Content
Jul 21, 2017
11:26 AM
So finally thanks to rguggisberg and my research.
found 2 possible solutions to this issue:
Please find the attached bat files. Rename the txt extension to bat extn.
RAM1 solution will work for all varieties of computer with multiple Dimm slots. CON: it takes few seconds to produce the output which is okay.
RAM2 solution (wmic memorychip get capacity) gives you the capacity of each Dimm (which will work fine, if you have only one Dimm installed but gives you one value per Dimm if there is installed more than one). It instantly gives the result.
To get the size of total memory use RAM1(wmic computersystem get TotalPhysicalMemory).
CON: it takes few seconds to produce the output which is okay.
![](/legacyfs/online/vb/11370_RAM2.txt)
found 2 possible solutions to this issue:
Please find the attached bat files. Rename the txt extension to bat extn.
RAM1 solution will work for all varieties of computer with multiple Dimm slots. CON: it takes few seconds to produce the output which is okay.
RAM2 solution (wmic memorychip get capacity) gives you the capacity of each Dimm (which will work fine, if you have only one Dimm installed but gives you one value per Dimm if there is installed more than one). It instantly gives the result.
To get the size of total memory use RAM1(wmic computersystem get TotalPhysicalMemory).
CON: it takes few seconds to produce the output which is okay.
- Mark as New
- Subscribe
- Mute
- Permalink
- Report Inappropriate Content
Jul 21, 2017
11:28 AM
rguggisberg wrote:
Depends. If you can live with the long number, yes.
@ECHO OFF & for /f %%A in ('wmic computersystem get TotalPhysicalMemory') do if not "%%A"=="TotalPhysicalMemory" echo(%%A >>"%Tempfile%"
Of course you need to replace %TempFile% above as needed.
Note that we have to use >> to append to the file. This is because wmic ouputs a LF or something at the end that the FOR loop does not interpret as an End Of Line... so we can't just re-write the file for each iteration of the loop. Because of this you will have to delete the temp file if it is present before you run this (good practice anyway).
You are great sir 🙂 Appreciate your help. Saved my day
![](/skins/images/CC38E504FC9E1309DC48ACFEB4925670/responsive_peak/images/icon_anonymous_message.png)