[gnuwin32] sed & variable %TIME%

HI..

I made ".bat" in windows 2003 , with

set TIEMPO1= %TIME% | sed -e "s/://g" -e "s/,//g"
echo valor de tiempo1 = %TIEMPO1%

when i execute this, the result is

but if i open cmd, and execute en line command this..

G:\>echo %TIME% | sed -e "s/://g"  -e "s/,//g"
12390841

anyone have idea, what's happening?

%TIME% | command is not the same thing as echo %TIME% | command . Without the echo, nothing gets fed into sed.

On my system, the date contains . too, so you you'd want to rip that out as well.

You can simplify your sed expression into -e "s/[:,.]//g"

You can't set variables in that fashion anyway. Windows CMD doesn't have backticks. It does have many strange options to SET and FOR some of which might be useful here.

---------- Post updated at 10:17 AM ---------- Previous update was at 10:10 AM ----------

'for' does have something like backticks but pipes don't work in it, and file redirection doesn't work outside of it...

---------- Post updated at 10:23 AM ---------- Previous update was at 10:17 AM ----------

This kludge works.

echo "%TIME%" | sed -e "s/[:,.]//g" > file.tmp
for /F %A in (file.tmp) DO SET TIEMPO1=%A
del /F /Q file.tmp

HI

thanks, so is working

echo %TIME% | sed -e "s/[:,.]//g" > file.tmp

for /F %%A in (file.tmp) DO SET TIEMPO1=%%A
del /F /Q file.tmp
echo valor de tiempo1 = %TIEMPO1%

But my original idea is not having to use a file ...

my "prueba.bat"

@ECHO OFF
echo ----------- TIEMPO -----------------
set TIEMPO= %TIME% 
echo valor de tiempo =  %TIEMPO%

echo ----------- TIEMPO1 -----------------
rem "does work in console with a ECHO  forward"
set TIEMPO1= %TIME% | sed -e "s/[:,.]//g"

echo valor de tiempo1 = %TIEMPO1%

echo ----------- TIEMPO2 -----------------

echo %TIME% | sed -e "s/[:,.]//g" > file.tmp

for /F %%A in (file.tmp) DO SET TIEMPO2=%%A
del /F /Q file.tmp
echo valor de tiempo2 = %TIEMPO2%
pause

and this is the output

----------- TIEMPO -----------------
valor de tiempo =   15:27:34,39
----------- TIEMPO1 -----------------
valor de tiempo1 =
----------- TIEMPO2 -----------------
valor de tiempo2 = 15273453
Press any key to continue . . .

whatever, I would like to make it work without using a file.

I know. The closest CMD has to backticks is FOR though, which only has one way to run an external command, doesn't support redirection or pipes inside it, and doesn't support redirection or pipes outside it. If sed would accept a string from the commandline instead of stdin, it'd be possible.

C:\>set t=%time::=%

C:\>set t=%t:,=%

C:\>echo %t%
20570193
1 Like

WOW . it's good

thanks