string manipulation in command promt

Answered string manipulation in command promt

  • Monday, September 17, 2012 5:25 AM
     
     

    Hi,(command prompt)

    I want to search for the string "virtual" in "system model" attribute of 'sysinfo' command. The command should be successful if 'virtual' is found in the 'system model: -------------------------' i.e. output of the systeminfo. It should not search for 'virtual' in whole output of systeminfo command but should do in system model attribute only.

    for command --systeminfo | findstr /i "system model" 

    I will get something like--- System Model:              HP Compaq dc7800p Small Form Factor

    in the above line of the output i want to search for string virtual, and want to manipulate using errorlevel.  So please help me to do this.

    following is the one i tried which was not correct.

    Or help me if i can use regular expressions

    systeminfo | findstr /i /R  "system model: virtual machine" > nul
    if %errorlevel% == 0 (
    echo virtual machine
    ) ELSE (
    echo physical machine
    )

    Thanks in advance

All Replies

  • Monday, September 17, 2012 6:06 AM
     
     Answered

    In your string make sure you account for the spaces.

    For example in my case when i run it as following i get one line in return:

    systeminfo | findstr /R /I /X "System Model:              Studio XPS 7100"

    When i run it as this then it does't work

    systeminfo | findstr /R /I /X "System Model:   Studio XPS 7100"

    • Marked As Answer by RameshLD Monday, September 17, 2012 6:10 AM
    •  
  • Monday, September 17, 2012 6:11 AM
     
     Answered
    thanx, helpful
    • Marked As Answer by RameshLD Monday, September 17, 2012 6:11 AM
    •