The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Compare date from db2 table to yesterday's Unix system date sasaliasim Shell Programming and Scripting 9 3 Days Ago 08:37 PM
Perl: Extracting date from file name and comparing with current date MKNENI Shell Programming and Scripting 4 03-26-2008 01:01 PM
date issue-find prevoius date in a patricular format bsandeep_80 UNIX for Advanced & Expert Users 3 11-15-2007 05:42 PM
Changing Creation Date to a Prespecified Date of a File In Unix monkfan UNIX for Dummies Questions & Answers 4 11-28-2006 04:15 AM
a simple way of converting a date in seconds to normal date travian HP-UX 2 11-23-2006 09:25 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 01-01-2008
Registered User
 

Join Date: Jan 2008
Posts: 3
sed, date and /&

Hi,

Code:
$ echo 1 titi | sed -e "s/1/$(echo \&)/"
1 titi
but

Code:
$ echo 1 titi | sed -e "s/1/$(date \&)/"
date: invalid date `&'
 titi
how can i do for handle '\&' with date ?

Thx
Reply With Quote
Forum Sponsor
  #2  
Old 01-01-2008
Moderator
 

Join Date: Dec 2003
Location: /dev/fl
Posts: 1,061
What exactly are you trying to achive with this code?
Reply With Quote
  #3  
Old 01-19-2008
Registered User
 

Join Date: Jan 2008
Posts: 3
Use case is not important, this is just one example.

I just wanna use the seed replacement special character & with the date command, like with echo.
Reply With Quote
  #4  
Old 01-19-2008
Moderator
 

Join Date: Dec 2003
Location: /dev/fl
Posts: 1,061
You are passing an invalid argument to the date utility as in "date 1", hence the error.

Code:
$ echo 1 titi | sed -e "s/1/$(date \&)/"
date: illegal time format
usage: date [-ajnu] [-d dst] [-r seconds] [+format]
       date -b [-ajnu] [-d dst] [-t west] [+format] [[[[[[cc]yy]mm]dd]HH]MM[.SS]
       date [-ajnu] [-d dst] [-t west] [+format] [mmddHHMM[[cc]yy]]
 titi
Reply With Quote
  #5  
Old 01-20-2008
Registered User
 

Join Date: Jan 2008
Posts: 3
fpmurphy, thx for the reply.

With a good argument, that still doesn't work for me.

Code:
echo 01201300 titi | sed -e "s/01201300/$(date \&)/"

date: invalid date `&'
 titi
GNU bash, version 3.2.25(1)-release (x86_64-pc-linux-gnu)
Reply With Quote
  #6  
Old 01-20-2008
radoulov's Avatar
addict
 

Join Date: Jan 2007
Location: Milano, Italia/Варна, България
Posts: 1,933
Do you want an output line this?

Code:
$ echo 08150000 titi | sed "s/08150000/$(date &)/"
Fri Aug 15 00:00:08 WEDT 2008 titi
This will change the machine's date

Last edited by radoulov; 01-20-2008 at 07:07 AM.
Reply With Quote
  #7  
Old 01-20-2008
Perderabo's Avatar
Unix Daemon
 

Join Date: Aug 2001
Location: Washington DC Area
Posts: 8,667
sncr24, your question does not make sense. That's why we cannot answer it.
Code:
$ echo 1 titi
1 titi
$ echo 1 titi | sed "s/1/&/"
1 titi
Those 2 command lines have the same output because the sed command makes no change to the text. The ampersand represents the matched field. Normally, you might do something like this...
Code:
$ echo 1 titi | sed -e "s/1/=&=&=/"
=1=1= titi
$
Getting back the the original sed command, which already does nothing, you can replace one of the characters in the sed command with an echo statement and that is what you did with
Code:
$ echo 1 titi | sed -e "s/1/$(echo \&)/"
1 titi
This continues to give the same output as a simple "echo 1 titi" but it watses even more time. Replacing the echo statement with an invocation of date is even more strange, but it can be done because "date" can be forced to behave a little bit like "echo".
echo \&
date +\&
both output a single ampersand. So both
Code:
echo 1 titi | sed -e "s/1/$(echo \&)/"
echo 1 titi | sed -e "s/1/$(date  +\&)/"
are ways to construct a sed command that will not do anything. But even though we got date to behave a liitle bit like echo, this won't be possible with all of the other unix commands.

I do not know what you are try to do, but I hope this helps move you toward fufilling your requirements. (Whatever they may be...)
Reply With Quote
Google The UNIX and Linux Forums
Reply

Tags
linux

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 07:33 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0