![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
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 |
|
||||
|
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
|
![]() |
| Bookmarks |
| Tags |
| mtime |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|