Echo Parse Cmd line

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
booga73
Posts: 108
Joined: 30 Nov 2011 16:16

Echo Parse Cmd line

#1 Post by booga73 » 31 Jan 2014 21:22

hello,

I have this line:

Code: Select all

echo for /F "tokens=1-4 delims=:.," %%a in ("%time%") do ( >> c:\temp1a\%Pro1%.bat


which at the command line parses this to my .bat file:
    for /F "tokens=1-4 delims=:.," %%a in ("21:13:26.36") do (

I've tried several options such as an extra % in %%a and time, ie.

Code: Select all

echo for /F "tokens=1-4 delims=:.," %%%a in ("%%time%%") do ( >> c:\temp1a\%Pro1%.bat


but my results in %pro1%.bat show the following:

Code: Select all

for /F "tokens=1-4 delims=:.," %%%a in ("%21:17:43.54%") do (


Now, the end result which I'm looking for when I parse my command line:

Code: Select all

echo for /F "tokens=1-4 delims=:.," %%a in ("%time%") do ( >> c:\temp1a\%Pro1%.bat


I would like to get:

Code: Select all

for /F "tokens=1-4 delims=:.," %%a in ("%time%") do (
inside my %Pro1%.bat file.

this is an unusual request for support.... v/r Booga

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Echo Parse Cmd line

#2 Post by foxidrive » 31 Jan 2014 22:05

You want to echo batch code into another batch file, correct?

Code: Select all

@echo off
echo for /F "tokens=1-4 delims=:.," %%%%a in ("%%time%%") do ( >> Pro1.bat

booga73
Posts: 108
Joined: 30 Nov 2011 16:16

Re: Echo Parse Cmd line

#3 Post by booga73 » 31 Jan 2014 22:37

Hi Foxidrive,

I found this post just about half hour ago... :lol: http://stackoverflow.com/questions/1922 ... as-literal

I appreciate your help too though.

I was at the command prompt and seeing different results as to what I would put into a batch file.

Similiar instance to what you posted too :P

Code: Select all

@echo off & echo for /F "tokens=1-4 delims=:.," %%%%a in ("%%time%%") do ( >> c:\temp1a\%Pro1%.bat


I ran a full test in my script an came up with the results, thank you!!

v/r Booga

booga73
Posts: 108
Joined: 30 Nov 2011 16:16

Re: Echo Parse Cmd line

#4 Post by booga73 » 01 Feb 2014 19:44

I'm completely stumped on this piece, 1 liner. . . . the problem is the ^ symbol that's causing a headache :(

Not sure, if you can assist with this line of code to parse:

all from a batch file, i.e. test.bat

Code: Select all

@echo & echo for /f %%%%a in ('type "%%file%%" ^^^^^|find "" /v /c') do set /a cnt=%%%%a >> testBt1.bat


outputs this:

Code: Select all

for /f %%a in ('type "%file%" ^^|find "" /v /c') do set /a cnt=%%a


but I need this out put instead:

Code: Select all

for /f %%a in ('type "%file%" ^|find "" /v /c') do set /a cnt=%%a


v/r Booga

Squashman
Expert
Posts: 4488
Joined: 23 Dec 2011 13:59

Re: Echo Parse Cmd line

#5 Post by Squashman » 01 Feb 2014 20:05

This works for me.

Code: Select all

@echo off
echo for /f %%%%a in ('type "%%file%%" ^^^|find /v /c ""') do set /a cnt=%%%%a >> testBt1.bat

booga73
Posts: 108
Joined: 30 Nov 2011 16:16

Re: Echo Parse Cmd line

#6 Post by booga73 » 02 Feb 2014 16:40

Great, thank you; Squashman, your input did work.

Post Reply