reformat date from istat


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting reformat date from istat
# 1  
Old 12-02-2010
reformat date from istat

I would like to determine if a file is older than a particular date. I found that istat will let me see the date and time of a file older than a year, but I need to change the format. Could anyone help me reformat the following date to a variable (a one liner would be great).

Output from istat - Last modified: Sat Oct 10 01:37:54 EDT 2009

capture date to a variable as - 200910100137 (yyyymmddHHMM)
# 2  
Old 12-02-2010
if you have gnu date this should do it:

Code:
MODDATE=$(date --date "$(istat FILENAME | awk -F "\t" '/Last modified/ { print $2}') " +%Y%m%d%H%M)

If you get date: Not a recognized flag, then we really don't have a 1 liner any more:

Code:
$ cat ISO2ymd.awk
awk -F "[: ]" ' BEGIN {
   D["Jan"]=1;  D["Feb"]=2;   D["Mar"]=3;   D["Apr"]=4;
   D["May"]=5;  D["Jun"]=6;   D["Jul"]=7;   D["Aug"]=8;
   D["Sep"]=9;  D["Oct"]=10;  D["Nov"]=11;  D["Dec"]=12; }
{ printf "%04d%02d%02d%s%s\n", $9, D[$2], $4, $5, $6; }' -
 
$ MODDATE=$(istat FILENAME | awk -F "\t" '/Last modified/ { print $2}' | ./ISO2ymd.awk)


Last edited by Chubler_XL; 12-02-2010 at 09:26 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Red Hat

CENTOS - istat

Hi, I am using CENTOS and for now, I am not able to install or to configure the istat command on Linux. So, is there a way to do the same that the shell is doing below, but not using istat command? I would appreciate any help on it. #!/bin/sh HOUR=0 MONTHN=0 if then : else ... (10 Replies)
Discussion started by: brjohnsmith
10 Replies

2. Shell Programming and Scripting

Parse and reformat

Trying to parse column C ($3) of the attached file (104 rows). The data is in the below format all in a string. Each string would be a separate row with the data in column A ($1) and column B ($2) being the header. All the data is in seperate columns as well. Thank you :). ACTA 59... (9 Replies)
Discussion started by: cmccabe
9 Replies

3. Shell Programming and Scripting

Please help me reformat this file

I am working with a file of the form; 4256 7726 1 6525 716 1 7626 0838 1 8726 7623 2 8625 1563 2 1662 2628 3 1551 3552 3 1542 7984 ... (3 Replies)
Discussion started by: digipak
3 Replies

4. UNIX for Advanced & Expert Users

reformat ps output

I often use "ps -ef" command to list all running processes. Now i want to customize the output to show only 2 parts: CMD and UID as below: /bin/bash /usr/bin/run-parts /etc/cron.weekly root /usr/sbin/httpd apache /usr/sbin/httpd apache /usr/sbin/httpd apache I use ps -ef | awk '{print $8"... (3 Replies)
Discussion started by: fongthai
3 Replies

5. Shell Programming and Scripting

reformat date, awk and sed

The command below is getting me the output I need. awk -F"," ' { if ($6 = 475) print "@@"$3 " " "0000" $10 "0" $1 "00000000" $8}' ${DIR1}${TMPFILE1} | sed -e 's/@@1//g' > ${DIR2}${TPRFILE} Output: 900018732 00004961160200805160000000073719 Now I need to incorporate... (5 Replies)
Discussion started by: mondrar
5 Replies

6. UNIX for Advanced & Expert Users

istat ??

I got the command : istat filename shows all the file details like owner and group name. But i want to know, who has accessed the file last time. As istat shows the name of owner of that file and name of the group. istat does lots of my work but i want to know who has accessed my file... (2 Replies)
Discussion started by: varungupta
2 Replies

7. UNIX for Advanced & Expert Users

istat ??

I got the command : istat filename shows all the file details like owner and group name. But i want to know, who has accessed the file last time. As istat shows the name of owner of that file and name of the group. istat does lots of my work but i want to know who has accessed my file... (0 Replies)
Discussion started by: varungupta
0 Replies

8. UNIX for Advanced & Expert Users

HP LC2000 has message: istat=0a: LSS_PAR on ha=1 sist0=41

I have a HP Netserver 2000 running SCO UNIX 5.0.6. I get the message: istat=0a: LSS_PAR on ha=1 sist0=41 sist1=00 !!!! dstat =81 on ha=1 has DS_OPC while WAIT DISCONNECT, rp=c014f8co dsp=FD on path=1, newdsp=FD064600 WARNING: Parity Error MSG OUT=00000006 Failed, 1code=80000002 on ha=1 id... (0 Replies)
Discussion started by: dmksh
0 Replies

9. UNIX for Dummies Questions & Answers

Date Reformat

Hello, I have a .CSV file with 10+ datetime columns. The way the data is stored in these columns are - 4/4/2006 3:45:30 PM I want the single digits to be left padded with a zero so the above looks like 04/04/2006 03:45:30 PM As the dates and times are different throughout the file... (2 Replies)
Discussion started by: F-1
2 Replies

10. Shell Programming and Scripting

reformat the file

Hi all, I ran into this problem, hope you can help I have a text file like this: Spriden ID First Name Last Name Term Code Detail Code Amount Trans Date Description ... (3 Replies)
Discussion started by: CamTu
3 Replies
Login or Register to Ask a Question