Want it to read the file name and then append date stamp at the end of file?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Want it to read the file name and then append date stamp at the end of file?
# 1  
Old 06-16-2014
Want it to read the file name and then append date stamp at the end of file?

I was thinking something like

Code:
for i in `find . -name "*.log.Z"`; do mv $i name.log.Z

or something like that?

Last edited by Don Cragun; 06-16-2014 at 05:54 PM.. Reason: Add CODE tags.
# 2  
Old 06-16-2014
Code:
for i in `find . -name "*.log.Z"`; 
do 
  mv $i $i`date +_%m_%d_%y_%H_%M`
done

this renames foo.log.Z -> foo.log.Z_06_16_2014_13_22, the current time/date
# 3  
Old 07-08-2014
What about the date and time that's on the time stamp? How do you do that?
# 4  
Old 07-08-2014
If you have gnu date (supports the --reference= option) you could do:

Code:
find . -name "*.log.Z" | while read fname
do
    mv "$fname" "$fname"$(date --reference="$fname" +_%m_%d_%y_%H_%M)
done


Last edited by Chubler_XL; 07-08-2014 at 05:49 PM.. Reason: Option is reference not file
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Append orginal file date to end of file

Trying to process 1000 or so files. Take original date and append to end of file. Like so: tstpls42.bas tstpls42.bas.Sep-11--2011 Been working along these lines: date=`ll tstpls42.bas |cut -c 46-57 |sed -e 's/]/\-/g' | grep -v '^$'` for i in *.bas ; do j=`ll $i /hpdump/b1 | awk... (1 Reply)
Discussion started by: joeadmin
1 Replies

2. Shell Programming and Scripting

Perl:Script to append date and time stamp

Help with Perl script : I have a web.xml file with a line <display-name>some_text_here</display-name> Need to append the current date and time stamp to the string and save the XML file Something like <display-name>some_text_here._01_23_2014_03_56_33</display-name> -->Finally want... (5 Replies)
Discussion started by: gaurav99
5 Replies

3. Emergency UNIX and Linux Support

How to append date and time stamp before the two extensions?

hi, i have some file names. my file names are as follows: c_abc_new.txt.xls c_def.txt.xls i want to append date time stamp in the below manner. c_abc_new_YYYYMMDD_HH24MISS.txt.xls c_def_YYYYMMDD_HH24MISS.txt.xls check the two input file names, they differ in naming. the 1st file name... (9 Replies)
Discussion started by: Little
9 Replies

4. Shell Programming and Scripting

append date time stamp via ftp script

I have searched several thread and not found my solution, so I am posting a new qustion. I have a very simple script on an AIX server that FTPs 2 files to a MS FTP server. These 2 files are created on the AIX server every hour, with a static name. I need to FTP the files to the MS server, but... (1 Reply)
Discussion started by: sknisely
1 Replies

5. UNIX for Dummies Questions & Answers

How can I append a text at end of file after displaying the file

I have a file "sample.txt" with the content as below: Hi This is a Sample Text. I need a single command using cat which serve the following purpose. 1.display the contents of sample.txt 2.append some text to it 3. and then exit But, all should be served by a sinle command.:confused: (1 Reply)
Discussion started by: g.ashok
1 Replies

6. Solaris

gzip a file and append creation date stamp to file

I want to gzip a file and append the creation date to the end of the file. How can I accomplish this task. Basically they are log files which need a creation date stamp appended to make sure they do not overwrite other log files. -jack (3 Replies)
Discussion started by: jacktravine
3 Replies

7. Shell Programming and Scripting

Append to end of each line of file without a temp file.

Hello I am trying to append an incrimenting number to the end of each line I have it working with a temp file. But I want to do this without a temp file. a=1 cat "file" | while read LINE do echo "$LINE, $a" >> filewithnumbers a=`expr $a + 1` ... (4 Replies)
Discussion started by: rorey_breaker
4 Replies

8. UNIX for Dummies Questions & Answers

How to Zip the files from date Stamp to end date Stamp

Hi, I need to zip the list of files using from date Stamp to end date Stamp, How can I filter and make FromDate_EndDate.gzip? any idea? (1 Reply)
Discussion started by: redlotus72
1 Replies

9. Shell Programming and Scripting

Date Stamp on new file

Dear Gurus, I'm trying to move a number of files from one directory to another directory with a new date stamp. This is my script: #! /bin/csh Today_Date=`date +%Y%M%D` mv /usr/TRS/data/TS* /usr/TRS/backup/TS*.${Today_Date} when i run the script i'm getting the following errors: mv:... (14 Replies)
Discussion started by: lweegp
14 Replies

10. Shell Programming and Scripting

Append a field to the end of each line of a file based on searching another file.

Hi All, I have two comma separated value(CSV) files, say FileA and FileB. The contents looks like that shown below. FileA EmpNo,Name,Age,Sex, 1000,ABC,23,M, 1001,DES,24,F, ... (2 Replies)
Discussion started by: ultimate
2 Replies
Login or Register to Ask a Question