[gnuwin32] sed & variable %TIME%

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting [gnuwin32] sed & variable %TIME%
# 1  
Old 09-28-2011
[gnuwin32] sed & variable %TIME% {solved}


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
E:\Pruebas>set TIEMPO1= 12:41:54,54 | sed -e "s/://g" -e "s/,//g"
E:\Pruebas>echo valor de tiempo1 =
valor de tiempo1 =
but if i open cmd, and execute en line command this..
G:\>echo %TIME% | sed -e "s/://g"  -e "s/,//g"

anyone have idea, what's happening?

Last edited by upszot; 09-28-2011 at 05:07 PM.. Reason: solved
# 2  
Old 09-28-2011
%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

# 3  
Old 09-28-2011

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 ----------- TIEMPO -----------------
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%

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.
# 4  
Old 09-28-2011
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.
# 5  
Old 09-28-2011
C:\>set t=%time::=%

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

C:\>echo %t%

This User Gave Thanks to radoulov For This Post:
# 6  
Old 09-28-2011
WOW . it's good

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Passing variable as input & storing output in other variable

I have a below syntax its working fine... var12=$(ps -ef | grep apache | awk '{print $2,$4}') Im getting expected output as below: printf "%b\n" "${VAR12}" dell 123 dell 456 dell 457 Now I wrote a while loop.. the output of VAR12 should be passed as input parameters to while loop and results... (5 Replies)
Discussion started by: sam@sam
5 Replies

2. Shell Programming and Scripting

Trim sed output & assign to variable

Hi, I have the following command that parses an xml file to read a node <port>'s value. Hoever the output comes with spaces. My requirement is to trim the spaces around the value and assign to a variable. sed -n 's|<port>\(.*\)</port>|\1|p' ../cfg.xml How do I go about it? (6 Replies)
Discussion started by: sai2013
6 Replies

3. Shell Programming and Scripting

sed & areas respectively sed & pyramiding

Hello everyone, i wonder if someone could give me an advice regarding the following problem using sed. Given ist a structure as shown below: <aaa>text1<b>text2</b>text3<c>text4</c>text5</aaa> Now I want to change the outer tag from "aaa" to "new" and replace all tags inside the outer tags... (4 Replies)
Discussion started by: Donaldinho
4 Replies

4. Shell Programming and Scripting

sed -i '7 c\$variable' file ....(?!@#$%^&*!)

I have tried everything I can think of to get sed to change line N of a file to the contents of a variable. I have Googled the Internet, and I find lots of people telling how to use variables with the "Substitute" command, but no one telling how to use variables with the "Change" command. I... (4 Replies)
Discussion started by: Mr.Lauren
4 Replies

5. Shell Programming and Scripting

Insert a line including Variable & Carriage Return / sed command as Variable

I want to instert Category:XXXXX into the 2. line something like this should work, but I have somewhere the wrong sytanx. something with the linebreak goes wrong: sed "2i\\${n}Category:$cat\n" Sample: Titel Blahh Blahh abllk sdhsd sjdhf Blahh Blah Blahh Blahh Should look like... (2 Replies)
Discussion started by: lowmaster
2 Replies

6. Shell Programming and Scripting

Using SED on Windows xp-GnuWin32

I installed the GnuWin32 tools on my Windows XP system but I cannot .. for the life of me .. get the SED tool to work for me. All I need to do is remove blank lines for a text file. My script is ... sed -e '/^$/ d' xxx.txt > yyy.txt The error msg is: sed: -e expression #1, char 1: unknown... (1 Reply)
Discussion started by: HOLMBERG
1 Replies

7. Shell Programming and Scripting

Convert Epoch Time to Standard Date and Time & Vice Versa

Hi guys, I know that this topic has been discuss numerous times, and I have search the net and this forum for it. However, non able to address the problem I faced so far. I am on Solaris Platform and unable to install additional packages like the GNU date and gawk to make use of their... (5 Replies)
Discussion started by: DrivesMeCrazy
5 Replies

8. Shell Programming and Scripting

Help needed - Replacing all date & time occurrences in a file with a string using Sed

Hi, I am new to using Sed. I have a file containg lines like the following: INFORM----Test.pc:168:10/11/05 12:34:26 > some text goes here.. TRACE-----Test.pc:197:10/11/05 12:34:26 > some text goes here.. My requirement is to replace 10/11/05 12:34:26 with a string <RUNDATE> (including <... (4 Replies)
Discussion started by: Hema_M
4 Replies

9. UNIX for Dummies Questions & Answers

GnuWin32 sed 4.1.4 regexp matching

I am using GnuWin32 sed and am having trouble with the regexp - i.e., they don't behave the same way as in UNIX (POSIX and and all that). I have a stream of data, e.g.: 11111'222?'22'33?'333'44444'55555' I want to insert a \n after those apostrophes that are *not* preceded by a ?. ... (2 Replies)
Discussion started by: Simerian
2 Replies
Login or Register to Ask a Question