The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Convert String to Date ORatjeuh Shell Programming and Scripting 2 05-06-2008 03:49 AM
convert Julian date to calender date srikanthus2002 Shell Programming and Scripting 6 05-08-2007 03:27 AM
Newbie convert date ksh britney Shell Programming and Scripting 3 03-15-2006 07:55 AM
Convert UTC time to Date GNMIKE Shell Programming and Scripting 8 10-19-2005 11:43 PM
Date convert Help nzq71k UNIX for Dummies Questions & Answers 2 05-20-2003 01:25 PM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1  
Old 04-02-2008
Registered User
 

Join Date: Apr 2008
Posts: 7
Convert date from yymmdd to mm/dd/yy

Hi,
I have a file where each record has a date field in yymmdd format. How can I convert it to a new file with the date changed to mm/dd/yy and a space before and after?

Input file:
9S14BT080407000000
6S14YS080402000000
6S14CK080402000000

Output needed:
9S14BT 04/07/08 000000
6S14YS 04/02/08 000000
6S14CK 04/02/08 000000
Thanks for any help you can give me.
Reply With Quote
Forum Sponsor
  #2  
Old 04-02-2008
Moderator
 

Join Date: Feb 2007
Posts: 2,199
Can you show us how far you've gotten so far to solve the problem?

Regards
Reply With Quote
  #3  
Old 04-02-2008
Registered User
 

Join Date: Apr 2008
Posts: 7
I am not very familiar with scripting and I do not know where to begin. Please pardon my ignorance.
Reply With Quote
  #4  
Old 04-02-2008
Registered User
 

Join Date: Mar 2008
Location: Toronto, Canada
Posts: 66
Try:
Code:
sed 's=\(......\)\(..\)\(..\)\(..\)=\1 \4/\2/\3 =' myfile >newfile
Reply With Quote
  #5  
Old 04-02-2008
Registered User
 

Join Date: Apr 2008
Posts: 7
Wow! That's great. I will work on understanding it now. Just one thing...
The sequence is off. It should be mm/dd/yy but it is dd/yy/mm.

6U1401 15/08/03 000000
6U1401 24/08/02 000000
6U1401 12/08/03 000000
6U1401 11/08/04 000000
6U1401 28/08/02 000000
6U1401 15/08/04 000000

Thanks.
Reply With Quote
  #6  
Old 04-02-2008
Registered User
 

Join Date: Apr 2008
Posts: 7
Got it!
Just switch the sequesnce -
sed 's=\(......\)\(..\)\(..\)\(..\)\(..\)\(..\)\(..\)=\1 \3/\4/\2 ='

duh!!
Thanks so much! It works great.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 02:54 AM.


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

Content Relevant URLs by vBSEO 3.2.0