The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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 07:15 AM
changing the format of date nasirgondal Post Here to Contact Site Administrators and Moderators 1 06-08-2006 01:37 AM
Changing the format of date nhatch UNIX for Dummies Questions & Answers 4 04-11-2006 10:17 AM
Changing date format Sabari Nath S Shell Programming and Scripting 5 12-07-2005 03:38 AM
Changing the date format Dream86 Shell Programming and Scripting 10 06-08-2005 01:35 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 03-20-2008
trichyselva trichyselva is offline
Registered User
  
 

Join Date: Feb 2006
Posts: 65
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
  #2 (permalink)  
Old 03-20-2008
raman1605 raman1605 is offline
Registered User
  
 

Join Date: Aug 2007
Posts: 41
use this way

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

Join Date: Aug 2007
Location: Assam,India
Posts: 166
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
  #4 (permalink)  
Old 03-20-2008
trichyselva trichyselva is offline
Registered User
  
 

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

Join Date: Jan 2008
Posts: 55
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}'
  #6 (permalink)  
Old 03-20-2008
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,730
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
Closed Thread

Bookmarks

Tags
mtime

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 09:21 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0