File renaming with date timestamp


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting File renaming with date timestamp
# 1  
Old 08-05-2008
File renaming with date timestamp

Hi,

This is my script:

#! /usr/bin/ksh
cd /app/chdata/workflow/suppl/esoutput/spd/testing
for file in /app/chdata/workflow/suppl/esoutput/spd/testing
do
sort *.txt | awk '{ file=substr($0,1,2)".txt"; print >> file }'
mv *.txt file_`date +"%Y%m%d%H%M%S"`.txt
done


Here, I am trying to rename all the files say *.txt to *_date.txt.

However, Its throwing an error.

Please help.

Regards,
Sunitha
# 2  
Old 08-05-2008
what error ?

- nilesh
# 3  
Old 08-05-2008
You probably mean

Code:
for file in *.txt; do
  mv "$file" file_`date +"%Y%m%d%H%M%S"`.txt
done

The sort | awk seems to be entirely unrelated to this problem. It should not be inside the for loop if you don't really mean for it to also operate on each file in *.txt separately (then similarly using "$file" as the argument to sort instead of *.txt).
# 4  
Old 08-05-2008
Thanks for the reply
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Replacing Date in the file with Create date and timestamp

Hello, I have files that with a naming convention as shown below. Some of the files have dates in the file name and some of them don't have dates in the file name. imap-hp-import-20150917.txt imap-dell-gec-import-20150901.txt imap-cvs-import-20150915.txt imap-gec-import.txt... (8 Replies)
Discussion started by: Saanvi1
8 Replies

2. Shell Programming and Scripting

File Timestamp and date comparsion

Hi, I have many files in the source directory but I need to process with the latest timestamp file. I am using linux operating system. i want extract the file created timestamp( Ext_File_create_date=) With this format YYYYMMDD- i have searched the relevent command in the unix forms but did... (5 Replies)
Discussion started by: onesuri
5 Replies

3. Shell Programming and Scripting

Check if a date field has date or timestamp or date&timestamp

Hi, In a field, I should receive the date with time stamp in a particular field. But sometimes the vendor sends just the date or the timestamp or correctl the date&timestamp. I have to figure out the the data is a date or time stamp or date&timestamp. If it is date then append "<space>00:00:00"... (1 Reply)
Discussion started by: machomaddy
1 Replies

4. Shell Programming and Scripting

To get max/min Date/Timestamp from a file

I want to get maximum/minimum date/timestamp from a data file ? Sample Input File ============= rec#,order_dt,ext_ts 1,2010-12-01,2010-12-01 17:55:23.222222 2,2011-11-05,2010-12-01 19:55:23.222222 3,2009-10-01,2010-12-01 18:55:23.222222 for above file Maximum Order_dt = 2011-11-05... (5 Replies)
Discussion started by: vikanna
5 Replies

5. Shell Programming and Scripting

Renaming a file and replacing the special character in the name with date

HI all, How can i rename some files and replace the special character in the name with todays date ex: Name#file1.txt Name#file2.txt to be renamed as Name.20091119.file1.txt Name.20091119.file2.txt (11 Replies)
Discussion started by: abhinav192
11 Replies

6. AIX

how to grep and compare timestamp in a file with the current date

I want to read a log file from a particular location.In the logfile , lines contains timestamp.I need to compare the timestamp in the logfile with the current date.If the timpestamp in the log file is less than 4 hours then i need to read the file from that location.Below is the file format.Please... (1 Reply)
Discussion started by: achu
1 Replies

7. UNIX for Dummies Questions & Answers

get a file date/timestamp

Could someone tell me how to get the date/time (to the second) a file was last modified? I need to know if a file was modified in the last 30 seconds from the system date. I'm on AIX/unix 4.3 (3 Replies)
Discussion started by: alex31
3 Replies

8. Shell Programming and Scripting

renaming the file with the timestamp

Hi, I am new to Shell programming, can any one help me with a shell program which can find a file and the rename it with a current datestamp and move it to a different directory. Advices/suggestions are welcome and Thanks in advance. :) (6 Replies)
Discussion started by: ajubi
6 Replies

9. Shell Programming and Scripting

how attached date when renaming log file

I want to rename a log file every weekend but also want to add date in the end of logfile name. How can i do that? Thanks (2 Replies)
Discussion started by: ukadmin
2 Replies

10. Shell Programming and Scripting

Creating file with date/timestamp in it

I need to create a file through a c-shell script which contains only the date and time that the file was created. Does anyone know a simple way to do this? Thank you, Paula (7 Replies)
Discussion started by: ccpjr29
7 Replies
Login or Register to Ask a Question