how to create file.txt and add current date in file content


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting how to create file.txt and add current date in file content
# 1  
Old 06-18-2009
how to create file.txt and add current date in file content

Hey guy,

how to make bash script to create foo.txt file and add current date into file content and that file always append.

example: today the script run and add today date into content foo.txt

and tomorrow the script will run and add tomorrow date in content foo.txt without remove today date.

thanks
boly
# 2  
Old 06-18-2009
You can just echo the date and append it to a file, if the file does not exist, then it is created.

Code:
-bash-3.2$ echo `date` >> dates.txt
-bash-3.2$ echo `date -d '+1 days'` >> dates.txt
-bash-3.2$ echo `date -d '+2 days'` >> dates.txt
-bash-3.2$ echo `date -d '+3 days'` >> dates.txt
-bash-3.2$ echo `date -d '+4 days'` >> dates.txt
-bash-3.2$ echo `date -d '+5 days'` >> dates.txt
-bash-3.2$ echo `date -d '+6 days'` >> dates.txt
-bash-3.2$ echo `date -d '+7 days'` >> dates.txt
-bash-3.2$ cat dates.txt
Thu Jun 18 04:27:24 CDT 2009
Fri Jun 19 04:27:36 CDT 2009
Sat Jun 20 04:27:49 CDT 2009
Sun Jun 21 04:27:52 CDT 2009
Mon Jun 22 04:27:55 CDT 2009
Tue Jun 23 04:27:58 CDT 2009
Wed Jun 24 04:28:00 CDT 2009
Thu Jun 25 04:28:04 CDT 2009

# 3  
Old 06-18-2009
what have u tried...
# 4  
Old 06-24-2009
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Copy the content from txt file and create a html file

I have a txt file with a list of error messages in a xml tag format, and each error message is separated with a identifier(endresult).Need to split that and copy and create a new html file.Error message has some special character. how to escape the special character and insert my data into the... (7 Replies)
Discussion started by: DevAakash
7 Replies

2. UNIX for Dummies Questions & Answers

Delete .txt file from current directory

I have created few text file during run time by redirecting the txt file echo USER_LIST_"$(date '+%d%h%Y')".csv > report_location.txt report_location.txt is creating in the same location where I run script home/script When I try to remove the txt file at the end of the... (3 Replies)
Discussion started by: stew
3 Replies

3. Shell Programming and Scripting

Need to append the date | abcddate.txt to the first line of my txt file

I want to add/append the info in the following format to my.txt file. 20130702|abcd20130702.txt FN|SN|DOB I tried the below script but it throws me some exceptions. <#!/bin/sh dt = date '+%y%m%d'members; echo $dt+|+members+$dt; /usr/bin/awk -f BEGIN { FS="|"; OFS="|"; } { print... (6 Replies)
Discussion started by: harik1982
6 Replies

4. Shell Programming and Scripting

Add current date to the data file

hi all Please assist i need to add current date as data to load to a database: the script is as follow: #!/bin/ksh DIR=/export/home/yani_m/scripts/scrip_out_put/ DIR2=/export/home/yani_m/scripts/scrip_out_put/calc/ Date=$1 File22="disk_"$Date Server=$2 iofiles=$DIR"/*"$Date"*_Ynr.dat"... (4 Replies)
Discussion started by: LucyYani
4 Replies

5. Shell Programming and Scripting

create txt file form data file and add some line on it

Hi Guys, I have file A.txt File A Data AK1521 AK2536 AK3164 I want create text file of all data above and write some data on each file. want Output on below folder /home/kka/out AK1521.txt Hi Welocme (3 Replies)
Discussion started by: asavaliya
3 Replies

6. UNIX for Dummies Questions & Answers

Select text between current date and output to new txt file

Hi guys, brand new to this thread and very very new to UNIX...so go easy please! Anyway I have a file that looks like this: >>-------------------------------------------------------------------------- Date/Time/Eng. : 2012-06-22 / 00:26 / DS Reported problem : (SD) ... (5 Replies)
Discussion started by: martin0852
5 Replies

7. UNIX for Dummies Questions & Answers

Move txt file to with current date appended to filename

I have multiple txt files which begin with the word "orders" in folder C:\source. I need to move the files to folder C:\dest and rename them to "process_<date>_<count>" So for example , if there are 3 files ordersa.txt , ordersb.txt and ordersc.txt in C:\source , after running the script I want... (7 Replies)
Discussion started by: johannd
7 Replies

8. Shell Programming and Scripting

Move txt file to with current date appended to filename

I have multiple txt files which begin with the word "orders" in folder C:\source. I need to move the files to folder C:\dest and rename them to "process_<date>_<count>" So for example , if there are 3 files ordersa.txt , ordersb.txt and ordersc.txt in C:\source , after running the script I want... (1 Reply)
Discussion started by: johannd
1 Replies

9. Shell Programming and Scripting

how to add current date to the file with sed

I want to add current date into the begin of the first line of the file. please show me the way please with "date" commond and sed (4 Replies)
Discussion started by: yanglei_fage
4 Replies

10. Shell Programming and Scripting

How to find the create time of a file if current date is in next month

Hi All, I want to find the time diffrence between currnt time and "abc.txt" file create time. I have solve that but if the abc.txt file created last month then is there any process to find the difftent? Exp: Create time of abc.txt is "Apr 14 06:48" and currect date is "May 17 23:47".... (1 Reply)
Discussion started by: priyankak
1 Replies
Login or Register to Ask a Question