![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum 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 |
| Conversion of .zip to .tar.Z format | eagercyber | Shell Programming and Scripting | 2 | 03-26-2008 05:11 AM |
| conversion of unix time format | sari | Windows & DOS: Issues & Discussions | 2 | 03-02-2008 11:33 PM |
| DateTime Format Conversion in a File | srikanthgr1 | Shell Programming and Scripting | 4 | 10-23-2007 09:58 AM |
| convert mmddyy date format to ccyyddd format?? | Bhups | Shell Programming and Scripting | 2 | 09-27-2006 08:30 PM |
| change the empty function from the old format to the new format | powah | Shell Programming and Scripting | 0 | 06-23-2005 09:17 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Date format conversion function
Hello,
does somebody knows about a function that would convert a date like: YYMMDD into a date like YYYY-MM-DD ? Thank you for your ideas |
| Forum Sponsor | ||
|
|
|
#2
|
||||
|
||||
|
yes, one of the 'functions' is 'sed'
|
|
#3
|
|||
|
|||
|
date format conversion
I can have either :
070829 --> I want 2007-08-29 890829 --> 1989-08-29 |
|
#4
|
||||
|
||||
|
Quote:
|
|
#5
|
|||
|
|||
|
The sed string to do that is worse than writing a shell function to do it IMO -
Code:
#!/bin/ksh
format ()
{
yr=`expr substr $1 1 2`
month=`expr substr $1 5 2`
day=`expr substr $1 7 2`
if [[ $yr > "30" ]] ; then
echo "19""$yr-$month-$day"
else
echo "20"$yr-$month-$day"
fi
}
new_date=$(format "041012")
echo $new_date
Last edited by jim mcnamara; 08-30-2006 at 12:48 PM. |
|
#6
|
||||
|
||||
|
Jim,
that was not the desired input format. given a sample input file 'mySampleFile.txt': Code:
070829 890829 050829 Code:
sed 's/\([^0].\)\(..\)\(..\)/19\1-\2-\3/g;s/\(0.\)\(..\)\(..\)/20\1-\2-\3/g' mySampleFile.txt |
|
#7
|
||||
|
||||
|
Quote:
Code:
echo "801229" | sed 's/\([^0].\)\(..\)\(..\)/19\1-\2-\3/g;s/\(0.\)\(..\)\(..\)/20\1-\2-\3/g' 198200--12--29 Code:
sed 's/\([^0].\)\(..\)\(..\)/19\1-\2-\3/g;s/^\(0.\)\(..\)\(..\)/20\1-\2-\3/g' mySampleFile.txt Tayyab |
||||
| Google The UNIX and Linux Forums |