How to write current Date dynamically in a file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to write current Date dynamically in a file
# 1  
Old 10-16-2006
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  
Old 10-16-2006
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  
Old 10-16-2006
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  
Old 10-16-2006
you are right
# 5  
Old 10-17-2006
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  
Old 10-17-2006
Code:
date +%a" "%b" "%d" "%Y

If above doesnt work check man date to get the correct options
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Replace date in file every day with current date

I Have text like XXX_20190908.csv.gz need to replace Only date in this format with current date every day Thanks! (1 Reply)
Discussion started by: yamasani1991
1 Replies

2. UNIX for Beginners Questions & Answers

“sed” replace date in text file with current date

We want to call a parameter file (.txt) where my application read dynamic values when the job is triggered, one of such values are below: abc.txt ------------------ Code: line1 line2 line3 $$EDWS_DATE_INSERT=08-27-2019 line4 $$EDWS_PREV_DATE_INSERT=08-26-2019 I am trying to write a... (3 Replies)
Discussion started by: pradeepp
3 Replies

3. UNIX for Beginners Questions & Answers

UNIX script to replace old date with current date dynamically in multiple files present in a folder

I am trying to work on a script where it is a *(star) delimited file has a multiple lines starts with RTG and 3rd column=TD8 I want to substring the date part and I want to replace with currentdate minus 15 days. Here is an example. iam using AIX server $ cat temp.txt RTG*888*TD8*20180201~... (1 Reply)
Discussion started by: Shankar455
1 Replies

4. Shell Programming and Scripting

Subtract a file's modification date with current date

SunOS -s 5.10 Generic_147440-04 sun4u sparc SUNW,SPARC-Enterprise Hi, In a folder, there are files. I have a script which reads the current date and subtract the modification date of each file. How do I achieve this? Regards, Joe (2 Replies)
Discussion started by: roshanbi
2 Replies

5. Shell Programming and Scripting

Get file name which include the current date

Hi, I'm trying to get the name of a file that has the current date in the name. The filename is on the form A<current date>01.DC, for example A2012110501.DC I have this script so far date +%y%m%d D=$(date +%y%m%d) N=A20$D echo $N N2={$N}01.DC echo $N2 And gets the following... (12 Replies)
Discussion started by: Immelstorn
12 Replies

6. UNIX for Dummies Questions & Answers

Delete a row from a file if one column containing a date is greater than the current system date

Hello gurus, I am hoping someone can help me with the required code/script to make this work. I have the following file with records starting at line 4: NETW~US60~000000000013220694~002~~IT~USD~2.24~20110201~99991231~01~01~20101104~... (4 Replies)
Discussion started by: chumsky
4 Replies

7. UNIX for Dummies Questions & Answers

Search for a file with Current Date

Hi, How can we search for a file with current date(sysdate). Actually i want the file name from a directory which was created today(current date). For example i have a dir /home/arch and i have files with name aglito03axyz.datetimestamp in this directory, but all these files were created... (7 Replies)
Discussion started by: sandeep_1105
7 Replies

8. Shell Programming and Scripting

to write a script to compare the file size in the current directory and previous dir

hi, i am new to this site. i want to write a script to compare the file size of the files in the current dir with the files in the previous directory. the files name will be same, but the filename format will be as xyzddddyymm.txt. the files will arrive with the month end date(i want to... (5 Replies)
Discussion started by: tweety
5 Replies

9. Shell Programming and Scripting

Perl: Extracting date from file name and comparing with current date

I need to extract the date part from the file name (20080221 in this ex) and compare it with the current date and delete it, if it is a past date. $file = exp_ABCD4_T-2584780_upto_20080221.dmp.Z really appreciate any help. thanks mkneni (4 Replies)
Discussion started by: MKNENI
4 Replies

10. Shell Programming and Scripting

File date vs Current date

I am a newbie in shell scripting, hope you can advice how can I compare the date/time of file extracted from 'll' and current system date/time. I have done the following: ll -rt > $FILE_AGE_LOG FILE_DATETIME=`more $FILE_AGE_LOG | head -02 | cut -c 45-57` It returns 'May 4 19:11'. If I... (4 Replies)
Discussion started by: trexlim
4 Replies
Login or Register to Ask a Question