![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| 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 |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
#1
|
|||
|
|||
|
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. |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
Can you show us how far you've gotten so far to solve the problem?
Regards |
|
#3
|
|||
|
|||
|
I am not very familiar with scripting and I do not know where to begin. Please pardon my ignorance.
|
|
#4
|
|||
|
|||
|
Try:
Code:
sed 's=\(......\)\(..\)\(..\)\(..\)=\1 \4/\2/\3 =' myfile >newfile |
|
#5
|
|||
|
|||
|
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. |
|
#6
|
|||
|
|||
|
Got it!
Just switch the sequesnce - sed 's=\(......\)\(..\)\(..\)\(..\)\(..\)\(..\)\(..\)=\1 \3/\4/\2 =' duh!! Thanks so much! It works great. |
|||
| Google The UNIX and Linux Forums |