How to iterate through a (semicolon;separated;list)

C

Csaba Gabor

Aaarggghh, sorry about the messed up title of my earlier post.
In the meantime, I have an answer, but it is not wholly satisfying
so I am modifying my question to ask whether there is any
command line 'replace string'?

The original question was to find out how I can iterate through
a list of semicolon separated values (where the list was coming
from a rows of a database). Here is my batch file solution:

FOR /F "tokens=1,* delims=:" %%G ^
IN ('c:\sqlite.exe c:\Mydb^
"SELECT Id||':'||myList FROM myTable;"')^
DO @FOR %%K IN (%%H) DO @ECHO %%G-^>%%K


But I am getting lucky with that inner FOR loop. Really
I would like to have a (regular expression preferred)
'replace string' in my arsenal.

Thanks for any tips,
Csaba Gabor
 
M

Marty List

Csaba Gabor said:
Aaarggghh, sorry about the messed up title of my earlier post.
In the meantime, I have an answer, but it is not wholly satisfying
so I am modifying my question to ask whether there is any
command line 'replace string'?

The original question was to find out how I can iterate through
a list of semicolon separated values (where the list was coming
from a rows of a database). Here is my batch file solution:

FOR /F "tokens=1,* delims=:" %%G ^
IN ('c:\sqlite.exe c:\Mydb^
"SELECT Id||':'||myList FROM myTable;"')^
DO @FOR %%K IN (%%H) DO @ECHO %%G-^>%%K


But I am getting lucky with that inner FOR loop. Really
I would like to have a (regular expression preferred)
'replace string' in my arsenal.

Thanks for any tips,
Csaba Gabor


This doesn't support regular expressions, but the only thing built-in to the
OS that I can think of is %name:a=b% syntax. This is from SET /?:

===================================================

%PATH:str1=str2%

would expand the PATH environment variable, substituting each occurrence
of "str1" in the expanded result with "str2". "str2" can be the empty
string to effectively delete all occurrences of "str1" from the expanded
output. "str1" can begin with an asterisk, in which case it will match
everything from the begining of the expanded output to the first
occurrence of the remaining portion of str1.

===================================================

You don't need to use the SET command, you can do it on the fly:

Echo %WINDIR:C:=D:%
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top