Re: How to through a semicolon separated list in a string
From: Csaba Gabor (news_at_CsabaGabor.com)
Date: 05/21/04
- Next message: Jim Davis: "Re: How to through a semicolon separated list in a string"
- Previous message: Csaba Gabor: "How to iterate through a (semicolon;separated;list)"
- In reply to: Matthias Tacke: "Re: How to through a semicolon separated list in a string"
- Next in thread: Jim Davis: "Re: How to through a semicolon separated list in a string"
- Reply: Jim Davis: "Re: How to through a semicolon separated list in a string"
- Reply: Matthias Tacke: "Re: How to through a semicolon separated list in a string"
- Messages sorted by: [ date ] [ thread ]
Date: Fri, 21 May 2004 22:22:24 +0200
Hey Matthias, thanks for the nice response, it
was really quite informative. And it has raised
more questions than it answered (I say that in a
good way - please see below)...
"Matthias Tacke" <Matthias@Tacke.de> wrote in message
news:c8lh41$7f0$02$1@news.t-online.com...
> "Csaba Gabor" wrote:
> Hello Csaba,
>
> >I'd like to be able to loop through all the entries in a semicolon
> >separated list in a single string. How should I do it?
> >
> >Specifically, I have an sqlite database where one of the fields is
> >a semicolon separated list of entries. I can easily get the nonempty
> >fields like so (and boy those line continuation characters (^) are
picky):
> >
> >FOR /F "tokens=1,* delims=:" %%G ^
> >IN ('c:\sqlite.exe c:\Mydb^
> >"SELECT Id||':'||myList FROM myTable;"')^
> >DO @ECHO %%G-^>%%H
>
> IMO formatting with breaks at natural points after ( and in front of )
> is better readable:
>
> @echo off
> FOR /F "tokens=1,* delims=:" %%G IN (
> 'c:\sqlite.exe c:\Mydb "SELECT Id||':'||myList FROM myTable;"'
> ) DO ECHO %%G-^>%%H
This is good to know, thanks. Can natural and batch be in the
same sentence?
> >But what I really need to be able to do is to loop through that
> >semicolon separated list in %%H (and stuff each element from
> >it into another variable, call it %%K). For my purposes it
> >would probably be sufficient if you could show me how to print
> >out individually each item in %%H on a separate line.
> >
> >Thanks,
> >Csaba Gabor (a batch file newbie)
> >
> Depending on format and content of the fields you have to prepare the
> lines before parsing.
> Are the fields quoted, are there empty fields with successing semicolons,
> are there semicolons or other difficult to handle chars inside fields?
As to my fields, they are not quoted but they may be NULL.
Turns out that's a good thing, because if myList is NULL,
so is the whole concatenated expression, so the FOR never
sees it. It just sees the lines that have well formed data (with
no ;; either).
> This batch could work if fields are not quoted.
>
> @echo off & setlocal enableextensions enabledelayedexpansion
> FOR /F "tokens=1,* delims=:" %%G IN (
> 'c:\sqlite.exe c:\Mydb "SELECT Id||':'||myList FROM myTable;"'
> ) DO (
> set line="%%H"
> set line2=!line:;=" "!
> Call :Parse !line2!
> )
> goto :eof
> :Parse
> IF NOT [%1] EQU [] echo/%~1 & shift & goto :Parse
>
I reposted because the title of this post is messed up and perhaps
my solution there is simpler, but yours is more educational for me.
In particular, if I read yours correctly, it is more general. The general
idea of what you're doing is clear, but the specifics interest me very
much. Where can I read the documentation about this ! form, which
I haven't seen before (I can't search for that on google, after all). It
seems like you're doing that replace that I'm after, yes? But I'd really
like to understand this exclamation syntax on both the second
set line, and the Call.
Also, what does the slash (/) after the echo and the tilde (~)
accomplish? I read that && is a conditional continuation (only
do the part to the right if the part to the left is not "false". Is
& simply a distinct command separator (which is what unconditional
continuation is)? Actually, if you have a recommended link that
explains these types of language basics, that would be just great.
Thanks, Csaba
> --
> Greetings
> Matthias________________________________________
> For help on nt commands enter in a cmd window:
> W2K>HH windows.chm::ntcmds.htm XP>HH ntcmds.chm
- Next message: Jim Davis: "Re: How to through a semicolon separated list in a string"
- Previous message: Csaba Gabor: "How to iterate through a (semicolon;separated;list)"
- In reply to: Matthias Tacke: "Re: How to through a semicolon separated list in a string"
- Next in thread: Jim Davis: "Re: How to through a semicolon separated list in a string"
- Reply: Jim Davis: "Re: How to through a semicolon separated list in a string"
- Reply: Matthias Tacke: "Re: How to through a semicolon separated list in a string"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|