Convert date from yymmdd to mm/dd/yy


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Convert date from yymmdd to mm/dd/yy
# 1  
Old 04-02-2008
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. Smilie
# 2  
Old 04-02-2008
Can you show us how far you've gotten so far to solve the problem?

Regards
# 3  
Old 04-02-2008
I am not very familiar with scripting and I do not know where to begin. Please pardon my ignorance.
# 4  
Old 04-02-2008
Try:
Code:
sed 's=\(......\)\(..\)\(..\)\(..\)=\1 \4/\2/\3 =' myfile >newfile

# 5  
Old 04-02-2008
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  
Old 04-02-2008
Got it!
Just switch the sequesnce -
sed 's=\(......\)\(..\)\(..\)\(..\)\(..\)\(..\)\(..\)=\1 \3/\4/\2 ='

duh!!Smilie
Thanks so much! It works great. Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Convert a date stored in a variable to epoch date

I am not able to pass date stored in a variable as an argument to date command. I get current date value for from_date and to_date #!/usr/bin/ksh set -x for s in server ; do ssh -T $s <<-EOF from_date="12-Jan-2015 12:02:09" to_date="24-Jan-2015 13:02:09" echo \$from_date echo... (7 Replies)
Discussion started by: raj48
7 Replies

2. Shell Programming and Scripting

Convert Date Format

Hello, I want to change the format of date value in variable. e.g. cur_date = '2013/03/13 14:24:50' (yyyy/mm/dd hh24:mi:ss) I want to change this to '13-MAR-2013 14:24:50 Following code coverts the current date to format I am looking for. But I do not know how this can be done for a date... (8 Replies)
Discussion started by: cartrider
8 Replies

3. Shell Programming and Scripting

Solved: Date: Convert m to mm

Hi all, I've searched through the forum and can't find a thread specific to this question: I have a CSV file with a date column, the dates I'm given from the original file look like: "m/dd/yyyy" (UNLESS it's a double digit month, like October, where it would then show up as "mm/dd/yyyy"). Is... (8 Replies)
Discussion started by: mtucker6784
8 Replies

4. Shell Programming and Scripting

Convert date arg to sql date

Doing a bcp load to sybase and need to convert datearg which comes in as 20130501 to 2013-05-01 which is the best way to do this (4 Replies)
Discussion started by: tasmac
4 Replies

5. UNIX for Dummies Questions & Answers

Unable to convert date into no. using date -d +%s syntax in ksh shell

hi friends, I m trying to write a script which compares to dates. for this i am converting dates into no using synatx as below v2=`date | awk '{print $2,$3,$4}'` v3=`date +%s -d "$v2"` this syntax is working in bash shell ,but fails in ksh shell. please suggest on this. (12 Replies)
Discussion started by: Jcpratap
12 Replies

6. Shell Programming and Scripting

Convert date

If I pass the value in the form YYYY/MM/DD(20100719) how to convert in the form 19\/Jul\/2010 (1 Reply)
Discussion started by: sandy1028
1 Replies

7. Shell Programming and Scripting

convert date format to mysql date format in log file

I have a comma delimited log file which has the date as MM/DD/YY in the 2nd column, and HH:MM:SS in the 3rd column. I need to change the date format to YYYY-MM-DD and merge it with the the time HH:MM:SS. How will I got about this? Sample input 02/27/09,23:52:31 02/27/09,23:52:52... (3 Replies)
Discussion started by: hazno
3 Replies

8. Shell Programming and Scripting

convert Julian date to calender date

Hi, I have script in unix which creates a julian date like 126 or 127 I want convert this julian date into calender date ex : input 127 output 07/may/2007 or 07/05/2007 or 07/05/07 rgds srikanth (6 Replies)
Discussion started by: srikanthus2002
6 Replies

9. UNIX for Dummies Questions & Answers

Date convert Help

Hi, I need to convert a char date to the datetime format for a table in sybase. I don't know how to do it, can anyone help me on this ? Thanks a lot !!!! :) (2 Replies)
Discussion started by: nzq71k
2 Replies
Login or Register to Ask a Question