![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Rules & FAQ | Contribute | Members List | Arcade | 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 !! |
|
|
||||
| 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 |
|
|
LinkBack | Thread Tools | 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 |
| Forum Sponsor | ||
|
|
|
|||
|
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
|
|||
| Google UNIX.COM |
| Tags |
| mtime |
| Thread Tools | |
| Display Modes | |
|
|