Files with date and time stamp


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Files with date and time stamp
# 1  
Old 09-24-2013
Files with date and time stamp

Hi Folks,

Need a clarification on files with date and time stamp.

Here is my requirement. There is a file created everyday with the following format "file.txt.YYYYMMDDHHMMSS".

Now i need to check for this file and if it is available then i need to do some task to the file.

I tried "file.txt.'date %Y%m%s'*" to check this, but this doesn't seem to work as the file gets created at different time everyday.

Can someone please help me out with the syntax to look for the file if it is available?

Thanks
# 2  
Old 09-24-2013
Code:
if test -f file.txt.$(date +%Y%m%d)*; then
  echo Found!
fi

Example:
Code:
$ touch file.txt.$(date +%Y%m%d%H%M%S)                        

$ ls file.txt*
file.txt.20130925030644

$ if test -f file.txt.$(date +%Y%m%d)*; then
>  echo Found!
>fi
Found!

This User Gave Thanks to Scott For This Post:
# 3  
Old 09-24-2013
You should be OK using: file.txt.$(date +%Y%m%d)*
This User Gave Thanks to Chubler_XL For This Post:
# 4  
Old 09-24-2013
Hi Folks,

Thanks much for the reply !!!

Here is my other request.

If the file with the date and time stamp is found, i need to rename the file with out changing the date and time.

For example, file.txt.20130925065543 should be renamed to file_first.txt.20130925065543

Please help me out with this.

Thanks
# 5  
Old 09-24-2013
Code:
$ echo $file
file.txt.20130925030644
$ mv "$file" "${file/./_first.}"

# 6  
Old 09-24-2013
Hi Folks,

To use this command mv "$file" "${file/./_first.}" i need to assign the file name to file variable first right ?

I am in the process of automating the step and I will not know what time the file will be created and it can be at anytime of the day. In this case how do i change the name of the file?

Thanks
# 7  
Old 09-25-2013
Assuming you have only one file created everyday
Code:
file=file.txt.$(date +%Y%m%d)*
test -f $file && mv "$file" "${file/./_first.}"

--ahamed
This User Gave Thanks to ahamed101 For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

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

2. Emergency UNIX and Linux Support

Is there any way to set the files modified date and stamp to last modifies time?

Actually i did modification in a file on server by mistake, now its showing current time stamp, is there any way to set the files modified date and stamp to last modifies time. Please advice here.Thanks in advance.:b: (7 Replies)
Discussion started by: saluja.deepak
7 Replies

3. Shell Programming and Scripting

Set date and time stamp of one file to another

Hi I use "touch -t xxxxxxxx" command to set date/time stamp of a file. My requirement is to read the date/time stamp of a file and apply it to another file. Is there anyway to do it simple instead of manually taking date/stamp of first file? TIA Prvn (2 Replies)
Discussion started by: prvnrk
2 Replies

4. Linux

rename files in a folder with date&time stamp

Hi, I want to rename all the files (more than 100 files) in a fodler to another folder with date&time stamp. foe eg, file1.dat file2.dat file3.dat .. to be renamed as file1100629_16_30_15.txt (yy-mon-dd_hh_mi_ss) file1100629_16_30_16.txt .. so on (2 Replies)
Discussion started by: feroz
2 Replies

5. UNIX for Advanced & Expert Users

rsync - date/time stamp

Hi, We are using RSYNC for syncing remote directories and working great. Our requirement is to have the destination files with date/time stamp of when they're copied on to the destination server, NOT the date/time stamps of source files/directories. As RSYNC, by default, preserving the same... (4 Replies)
Discussion started by: prvnrk
4 Replies

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

7. UNIX for Dummies Questions & Answers

Date/Time Stamp

Hi All, Wondering if there is have a date added at the end of a test string. I have a hypothetical text file day one: John Paul George When the file day one is output, I'd like it to read something like this: John 101406 Paul 101406 George 101406 Day two, when the same text file... (0 Replies)
Discussion started by: JimmyFlip
0 Replies

8. Shell Programming and Scripting

Insert Time and Date Stamp

I have a directory with following files in it ABC.000.DAT ABC.001.DAT ABC.002.DAT ABC.003.DAT I want to insert time and date stamp in file names like ABC.000.YYYYMMDDHHMM.DAT I able to insert the time and date stamp at the end of filename Kindly help (1 Reply)
Discussion started by: aajmani
1 Replies

9. Shell Programming and Scripting

Date Time Stamp

I'm trying to write a script that checks the DTS of a file the compares it to the current time. If greater that 60 mins has gone by and the file has not been written to alert. So far I have the time pulled from the file but I dont know how to compare the times against a 60 min difference. ... (2 Replies)
Discussion started by: jarich
2 Replies

10. UNIX for Dummies Questions & Answers

File date and time stamp

I have to capture the creation date and time stamp for a file. The ls command doesn't list all the required information. I need year, month, day, hour, minute and second. Any ideas... (1 Reply)
Discussion started by: Xenon
1 Replies
Login or Register to Ask a Question