The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Changing Creation Date to a Prespecified Date of a File In Unix monkfan UNIX for Dummies Questions & Answers 4 11-28-2006 03:15 AM
changing the format of date nasirgondal Post Here to Contact Site Administrators and Moderators 1 06-07-2006 10:37 PM
Changing the format of date nhatch UNIX for Dummies Questions & Answers 4 04-11-2006 07:17 AM
Changing date format Sabari Nath S Shell Programming and Scripting 5 12-06-2005 11:38 PM
Changing the date format Dream86 Shell Programming and Scripting 10 06-08-2005 10:35 AM

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 03-19-2008
Registered User
 

Join Date: Feb 2006
Posts: 40
changing the format of date in unix

When i execute the below command it is giving the timestamp in the format mentioned below

ls -ltr 1234.txt | awk 'BEGIN {FS=" "} {print $6" "$7" "$8}'
Mar 20 00:12

i want output in the format 200803200012

please help me how to do it
here year is not returned and i have to convert mar to 03

suggestions welcome

thanks in advance
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 03-19-2008
Registered User
 

Join Date: Aug 2007
Posts: 40
use this way

Code:
DATE="$(date '+%Y%m%d%M%S')"
echo $DATE
Reply With Quote
  #3 (permalink)  
Old 03-19-2008
jaduks's Avatar
Registered User
 

Join Date: Aug 2007
Location: Assam,India
Posts: 141
Code:
$ ls -l datediff.sh
-rw-r--r--  1 jsaikia staff 251 Mar 10 15:06 datediff.sh
$ ls -l datediff.sh --time-style=full-iso | awk '{print $6,$7}' | awk -F ":" '{print $1,$2}' | sed -e 's/-//g' -e 's/ //g'
200803101506
Your "ls" should support "--time-style=full-iso" for this to work.

//Jadu
Reply With Quote
  #4 (permalink)  
Old 03-20-2008
Registered User
 

Join Date: Feb 2006
Posts: 40
no the ls in my os doesnot support time-style=full-iso format
Reply With Quote
  #5 (permalink)  
Old 03-20-2008
Registered User
 

Join Date: Jan 2008
Posts: 52
Hope this works:

code:

ls -ltr data | awk 'BEGIN {FS=" "} {print $6" "$7" "$8}'|awk '$1 ~/'Feb'/{ print 200802$3}; $1 ~/Mar/{print 200803$2$3};$1 ~/Apr/{print 200804$2$3}'
Reply With Quote
  #6 (permalink)  
Old 03-20-2008
...@...
 

Join Date: Feb 2004
Location: NM
Posts: 3,493
You are going to have to use perl, python or C.
perl example -
Code:
#!/bin/ksh
dfmt()
{
	perl -e ' 
	         use POSIX qw(strftime);
			 $fmt="%Y%m%d%M%S";
			 $mtime=(stat $ARGV[0])[9];
			 ($sec,$min,$hour,$day,$mon,$yr,$wday,$yday,$dntcare)=localtime($mtime);
			 $result=
			      strftime($fmt,$sec,$min,$hour,$day,$mon,$yr,$wday,$yday,$dntcare);
			 print "$result";
			' $1
}

for file in `ls *.pl`
do
	echo "$file $(dfmt $file)"	
done
Reply With Quote
Google UNIX.COM
Reply

Tags
mtime

Thread Tools
Display Modes




All times are GMT -7. The time now is 01:27 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0