File Timestamp and date comparsion


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting File Timestamp and date comparsion
# 1  
Old 06-25-2012
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 not find relevent information.


Example:
Jun 23 10:10 new_file22062012101010.txt
Jun 24 11:15 new_file23062012111010.txt
Jun 25 09:10 new_file24062012111590.txt #latest file

Code:
################################################--
# Get the today date with YYYYMMDD format.
################################################--
Today_date=`date +Y%m%d`

################################################--
# Extract file created date with format YYYYMMDD
################################################--
Ext_File_create_date=                 #get the file created timestamp YYYYMMDD
################################################--
# Date comparision
################################################--


if [ "$Today_date" = "$Ext_File_create_date  ]
then
echo "today file arrived"
elce 
echo 'today file not arrrived"
fi

Thanks
Suri
# 2  
Old 06-25-2012
Quote:
Jun 25 09:10 new_file24062012111590.txt #latest file
There are two different dates in this record. Which of the two dates are you interested in?


What Operating System and version are you running and what Shell is this?
Also, do you have the GNU date command or Perl ?
# 3  
Old 06-25-2012
Hi,

Operating system -linux
Shell -bash

Example: This is the latest file. I need to get the file created date.
here file created date-Jun 25 ,Final output: 20120625

Jun 25 09:10 new_file24062012111590.txt #latest file
# 4  
Old 06-25-2012
Try this:
Code:
Ext_File_create_date=`echo *.txt | awk '{gsub(/\.[^.]*$/,"",$0); L=length;
    D=substr($0,L-9,4) substr($0,L-11,2) substr($0,L-13,2);
    if(0+D>M)M=D} END {print M}'`

# 5  
Old 06-26-2012
treat today date as 25-06-2012

here file created date-Jun 25 ,Final output: 20120625

Jun 25 09:10 new_file24062012111590.txt #latest file

i should get the output as 20120625 but using the below command i am getting the proper output
using the below command output-> 10101210
# 6  
Old 06-26-2012
Code:
$ echo "Jun 25 09:10 new_file24062012111590.txt" | awk '{gsub(/\.[^.]*$/,"",$0); L=length;
     D=substr($0,L-9,4) substr($0,L-11,2) substr($0,L-13,2);
     if(0+D>M)M=D} END {print M}'
20120624

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

File comparsion tool

Hi All, Please suggest some file comparison tool in Linux. The tool have the provision for command line option for file comparison and the output will be stored in to html file. Thanks in advance (2 Replies)
Discussion started by: k_manimuthu
2 Replies

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

3. UNIX for Dummies Questions & Answers

Help me in the Execution of Date comparsion

Hi , Please look into the query 1)Date format: mm/dd/yyyy  example (10/22/2013) 2) compare this date  with the System date  3) if the difference of dates less than 30 days. Then return true otherwise false. 4)commands date-d is not there in my unix version. 5)present version 6 6)using... (7 Replies)
Discussion started by: RaghavendraT
7 Replies

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

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

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 log file each line starts with 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... (1 Reply)
Discussion started by: achu
1 Replies

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

8. Shell Programming and Scripting

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 }' ... (3 Replies)
Discussion started by: Sunitha_edi82
3 Replies

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

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