Link to home
Start Free TrialLog in
Avatar of sda100
sda100Flag for United Kingdom of Great Britain and Northern Ireland

asked on

String manipulation in DOS (Batch)

Sample data I have to work with:

   abcd123, Joe Bloggs logging on to PC25 DOMAIN on <IP> on Thursday, November 2, 2006

What I want the output to look like:

   Joe Bloggs - Thursday, November 2, 2006

This is the code I have at the moment (%* is input data):

   set X=%*
   set X=%X: on =      %
   set X=%X: logging=      %
   for /f "tokens=1,4 delims=      " %%i in ("%X%") do echo %%i - %%j

This is what my output then looks like:

   abcd123, Joe Bloggs - Thursday, November 2, 2006

My question is, I can't work out how to get rid of the substring "abcd123, ".

Thanks,
Steve :)
ASKER CERTIFIED SOLUTION
Avatar of callrs
callrs

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of sda100

ASKER

Both the above solutions work on the premise of a fixed number of tokens, which I can't guarantee.  However, you gave me ideas for the solution, so I will share the points - thank you.  If you're interested, here is the part of my code that achieves what I want:

if "%*"=="" goto :eof
set X= %*
set X=%X: on =      %
set X=%X: logging=      %
for /f "tokens=4 delims=      " %%i in ("%X%") do set Y=%%i
set Y=%Y:~0,-12%
for /f "tokens=1 delims=      " %%i in ("%X%") do set X=%%i
:logformat_loop
set X=%X:~1%
echo %X% | find "," > nul
if not errorlevel 1 goto logformat_loop
set X=%X:~1%


Steve :)