'HELLO-1039-4019-3929'
'YES-1930-4910-4939'
with a variable number of characters before the first hyphen. I'd like
my command file to parse out and return to me the string 'HELLO' or
'YES': whatever exists before the first hyphen. Can someone point me in
the right direction of how to do this? Thanks much.
@echo off & setlocal enableextensions
::
:: Make a test file
echo HELLO-1039-4019-3929 > mytest.txt
echo YES-1930-4910-4939 >> mytest.txt
::
::
for /f "tokens=1 delims=-" %%a in ('type mytest.txt') do (
echo %%a
)
::
:: Clean up
for %%f in (mytest.txt) do if exist %%f del %%f
endlocal & goto :EOF
Output:
C:\_D\TEST>cmdfaq
HELLO
YES
All the best, Timo
--
Prof. Timo Salmi ftp & http://garbo.uwasa.fi/ archives 193.166.120.5
Department of Accounting and Business Finance ; University of Vaasa
mailto:t...@uwasa.fi <http://www.uwasa.fi/~ts/> ; FIN-65101, Finland
Useful script files and tricks ftp://garbo.uwasa.fi/pc/link/tscmd.zip
for /f "delims=-" %%i in (fileofstrings.txt) do echo %%i
single-% if executed from the prompt, double if executed as a line within a
batch scriptfile.
Assuming, in the absence of information, that the strings are in a file and
the the single-quotes that you have used are quoted examples of the
structure of the lines in the file.
If the single-quotes are actually the first character in the line, then
include a single-quote somewhere between the equal-sign and the
closing-double-quote of the "DELIMS" clause.
HTH
...Bill
In article <dl4tc5$ge4$2...@haavi.uwasa.fi>, t...@uwasa.fi says...
> Right, this looks great. Is there a way to do this without writing it
> out to a file? My initial string is simply the value of a variable.
>
In your extensive testing, did you try
for /f "tokens=1 delims=-" %%a in ("%myvariablename%") do echo %%a
HTH
...Bill
> Right, this looks great. Is there a way to do this without writing it
> out to a file? My initial string is simply the value of a variable.
Please don't take this the wrong way, but the general ideas should
be evident enough to continue from with one's own developments once
the essentials (in this case the for /f tokens delims) are given.
Let's bear in mind that this is not a helpdesk. Just a discussion
newsgroup. If you first are in a need of the very basics of script
writing you'll find it very useful to see the more than ample
material pointed to in
Windows Command Line Interface script programming links
http://www.uwasa.fi/~ts/http/http2.html#cmdscript
Meaning well.