The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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 and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Perl: Extracting date from file name and comparing with current date MKNENI Shell Programming and Scripting 4 03-26-2008 04:01 PM
check the current date file in directory pallvi SUN Solaris 2 01-04-2008 05:57 PM
how to check whether the given file is 5 weeks older than current date risshanth Shell Programming and Scripting 1 10-29-2007 04:53 AM
File date vs Current date trexlim Shell Programming and Scripting 4 05-04-2007 09:35 PM
how to give current date in file name? simurg11 UNIX for Dummies Questions & Answers 3 05-10-2005 09:09 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 10-16-2006
Sree_2503 Sree_2503 is offline
Registered User
  
 

Join Date: Oct 2006
Posts: 10
How to write current Date dynamically in a file

Hi,

I have a requirement where I need to write the current date to the file.
This remaining content of this file does not change and we use this file to concat with another one.

Only thng is that I need to write the date to say, record number 10 of this file everyday.
Can this be done in my ksh.

e.g

AADjndfj
dweced
dew
dswhdx
CURRENT DATE
xndxwdxew
cdfcedc
dcfecf
dcfdwq

Appreciate your responses.
Thanks,
Sree
  #2 (permalink)  
Old 10-16-2006
anbu23 anbu23 is offline Forum Advisor  
Registered User
  
 

Join Date: Mar 2006
Location: Bangalore,India
Posts: 1,398
Code:
sed "s/CURRENT DATE/`date`/" file >temp 
mv temp file
I assumed CURRENT DATE as a string in the file.

If you want to include after particular line

Code:
sed "10 i\\
`date`" file > temp
mv temp file
  #3 (permalink)  
Old 10-16-2006
Sree_2503 Sree_2503 is offline
Registered User
  
 

Join Date: Oct 2006
Posts: 10
Thanks Anbu.

just for my explanation (for an unix learner like me) -

This is going to replace the string 'CURRENT DATE' with the value of the current date - Am I right?
  #4 (permalink)  
Old 10-16-2006
anbu23 anbu23 is offline Forum Advisor  
Registered User
  
 

Join Date: Mar 2006
Location: Bangalore,India
Posts: 1,398
you are right
  #5 (permalink)  
Old 10-17-2006
Sree_2503 Sree_2503 is offline
Registered User
  
 

Join Date: Oct 2006
Posts: 10
Current Date - display

Hi Anbu,

This is giving me a value like as follows -

Tue Oct 17 16:53:45 EDT 2006

What if I want only 'Tue Oct 17 2006' to display. I dont want the hh:mm:ss EDT part.


Thanks
Sree.
  #6 (permalink)  
Old 10-17-2006
anbu23 anbu23 is offline Forum Advisor  
Registered User
  
 

Join Date: Mar 2006
Location: Bangalore,India
Posts: 1,398
Code:
date +%a" "%b" "%d" "%Y
If above doesnt work check man date to get the correct options
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 04:07 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0