Putting the Current -date in the Output File


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Putting the Current -date in the Output File
# 1  
Old 12-22-2011
Putting the Current -date in the Output File

Hi guys,

Just want to ask how can I make a script that will perform like this.

1. Execute the command
2. Then the output of the command will be redirected to a file
2. The file that has been created will have a date on it equivalent to the date and time it was created (or maybe after the command has been executed).


Please advice,
rymnd_12345
# 2  
Old 12-22-2011
Code:
 
echo "abc" > myfile$(date +%Y%m%d_%H%M%S)

This User Gave Thanks to itkamaraj For This Post:
# 3  
Old 12-22-2011
Well you didn't say using what, so I'll stick with the ever-wonderful bash. Set your outputfile name and then run the script as ./scriptname "INSERT YOUR COMMAND HERE" or simply edit the YOURCMDHERE part.

Code:
#!/bin/bash
if [[ $# > 0 ]]; then
  $@
else
  YOURCOMMANDHERE
fi > OUTPUT.$(date +%F_%T)

# 4  
Old 12-22-2011
Hi Guys,

Thanks for your help, what if my command is
Code:
history

Any suggestion?
Smilie


Br,
rymnd_12345
# 5  
Old 12-22-2011
Code:
history > output$(date +%Y%m%d_%H%M%S)

# 6  
Old 12-22-2011
Hi itkamaraj,

That will do it! Thanks!


Hi ryran,
thanks also!


br,
rymnd_12345
 
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. 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

4. 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

5. UNIX for Dummies Questions & Answers

Comparing Output Date to Current System Date

Hi Guys, Anyone who knows how to compare the current date with the a file containing a date, say for example I have a file that looks like this: Command was launched from partition 0. ------------------------------------------------ Executing command in server server6 Fri Dec 16... (7 Replies)
Discussion started by: rymnd_12345
7 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. Shell Programming and Scripting

putting color on output file script

do you have any simple script on how to change the color and font of a string in a script example echo "====================================" echo " sample color script" echo "====================================" echo " hello " echo " bye" on hello,... (3 Replies)
Discussion started by: lhareigh890
3 Replies

8. Shell Programming and Scripting

Prefix the current date and time to the output of ps

Hi, I need to write a script, that will take the current date, time, and the output from # ps -eo pid,tid,class,rtprio,ni,pri,psr,pcpu,stat,wchan:14,comm and spit it to a file, so it'll look like this... PID TID CLS RTPRIO NI PRI PSR %CPU STAT WCHAN COMMAND 1 1 TS... (2 Replies)
Discussion started by: Bloke
2 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

Putting screen output in a log file

I want to output screen messages to a logfile when executing an automated script. I have tried the script and command to do this but with no luck. Thanks, Nicole (5 Replies)
Discussion started by: nsutti
5 Replies
Login or Register to Ask a Question