Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to fetch the substring from the input string in command prompt

I have the following string

set var="/host=the_host/core-service=vault:add(vault-options=[("KEYSTORE_URL" => "C:\wildfly-15.0.1.Final\bin\vault\vault.keystore"),("KEYSTORE_PASSWORD" => "MASK-18BzezESSkb72WrhEf6Rsu"),("KEYSTORE_ALIAS" => "vault"),("SALT" => "1234abcd"),("ITERATION_COUNT" => "120"),("ENC_FILE_DIR" => "C:\wildfly-15.0.1.Final\bin\vault/")])"

I want to extract only the MASK-18BzezESSkb72WrhEf6Rsu value alone using windows batch. I have tried using the for but couldn’t find anything to fetch the password alone.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

@ECHO OFF
SETLOCAL

SET "string=/core-service=vault:add(vault-options=[("KEYSTORE_URL" => "C:\wildfly-8.2.1.Final\bin\vault\vault.keystore"),("KEYSTORE_PASSWORD" => "MASK-18BzezESSkb72WrhEf6Rsu"),("KEYSTORE_ALIAS" => "vault"),("SALT" => "1234abcd"),("ITERATION_COUNT" => "120"),("ENC_FILE_DIR" => "C:\wildfly-8.2.1.Final\bin\vault/")])"

SET "string=%string:"=%"
SET "string=%string:>=%"
SET "string=%string:<=%"
SET "string=%string:)=%"
SET "string=%string:(=%"

SET "password="

FOR %%e IN (%string%) DO IF DEFINED password (
  SET "password=%%e"
  GOTO found
 ) ELSE  IF /i "%%e"=="KEYSTORE_PASSWORD" SET "password=next"

ECHO password NOT found
GOTO :eof

:found
ECHO password is "%password%"

GOTO :EOF

Remove the awkward characters by uing string-substitution then run through the remaining list of words, if the string in the word before is found, set password as a flag, and grab the next one.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading