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
Change of date format svenkatareddy Shell Programming and Scripting 2 05-22-2008 11:58 PM
How Can we change the Date format from Variable laknar Shell Programming and Scripting 1 05-01-2008 11:47 PM
Move A File With Same Date,don't Change The Desitination Dir Date jee.ku2 UNIX for Dummies Questions & Answers 1 01-09-2008 09:42 AM
Change date format ust UNIX for Advanced & Expert Users 4 12-19-2007 01:17 PM
How to change it to the date format preethgideon UNIX for Dummies Questions & Answers 3 11-02-2006 04:11 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 06-09-2008
Registered User
 

Join Date: Jun 2008
Posts: 12
Stumble this Post!
script to change the date format in a file

i have many files with date format of 6-9-2008 and i want a script that can change the format to 2008-06-09

Thanks
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 06-10-2008
Moderator
 

Join Date: Dec 2003
Location: /dev/florida
Posts: 944
Stumble this Post!
Unless you provide an example of one or more of the files, it is difficult for anybody to help you.
Reply With Quote
  #3 (permalink)  
Old 06-10-2008
Registered User
 

Join Date: Apr 2008
Location: Bangalore
Posts: 120
Stumble this Post!
Hi

echo "6-9-2008" | sed 's/\(.\)-\(.\)-\(.*\)/\3-0\2-0\1/g'

It would be nice if u provide one file as an example as fpmurphy suggested.


Thanks
Penchal
Reply With Quote
  #4 (permalink)  
Old 06-10-2008
Registered User
 

Join Date: Jun 2008
Posts: 12
Stumble this Post!
Here are few examples

NO1A_iCP0041 52 6-9-2008 11 11 8
8


NO1A_iCP0041 52 6-11-2008 11 11 8 8



NO1A_iCP0041 52 9-20-2008 11 11
8 8


The dates are in M-D-YYYY format, I am trying to get it in a YYYY-MM-DD


Thanks
Reply With Quote
  #5 (permalink)  
Old 06-10-2008
robotronic's Avatar
Can I play with madness?
 

Join Date: Apr 2002
Location: Italy
Posts: 370
Stumble this Post!
Given this input file:

Code:
NO1A_iCP0041 52 6-9-2008 11 11 8 8
NO1A_iCP0041 52 6-11-2008 11 11 8 8
NO1A_iCP0041 52 9-20-2008 11 11 8 8
Try:
Code:
awk '{ split($3, d, "-"); $3=sprintf("%04d-%02d-%02d", d[3], d[1], d[2]); print }' input_file.txt
Reply With Quote
  #6 (permalink)  
Old 06-10-2008
Registered User
 

Join Date: Jun 2008
Posts: 12
Stumble this Post!
Quote:
Originally Posted by robotronic View Post
Given this input file:

Code:
NO1A_iCP0041 52 6-9-2008 11 11 8 8
NO1A_iCP0041 52 6-11-2008 11 11 8 8
NO1A_iCP0041 52 9-20-2008 11 11 8 8
Try:
Code:
awk '{ split($3, d, "-"); $3=sprintf("%04d-%02d-%02d", d[3], d[1], d[2]); print }' input_file.txt

What would i change when the data is pipe delimted

example

NO1A_iCP0041|52|11|11|8|8|6-9-2008
NO1A_iCP0041|52|11|11|8|8|6-11-2008
NO1A_iCP0041|11|11|8|8||52 9-20-2008

Thanks for the help
Reply With Quote
  #7 (permalink)  
Old 06-10-2008
Registered User
 

Join Date: Jun 2008
Posts: 12
Stumble this Post!
Quote:
Originally Posted by shehzad_m View Post
What would i change when the data is pipe delimted

example

NO1A_iCP0041|52|11|11|8|8|6-9-2008
NO1A_iCP0041|52|11|11|8|8|6-11-2008
NO1A_iCP0041|11|11|8|8||52 9-20-2008



Thanks for the help
also couple files like these

12|kenneth.ludlam@yahoo.com|Boston|iVPUd|MPDD|2-10-2007|2-11-2007|
12|kenneth.ludlam@yahoo.com|Boston|iVPUd|MPDD|12-9-2007|12-9-2007|
12|kenneth.ludlam@yahoo.com|Boston|iVPUd|MPDD|2-2-2007|2-2-2007|
Reply With Quote
Google The UNIX and Linux Forums
Reply

Tags
solaris

Thread Tools
Display Modes




All times are GMT -7. The time now is 04:45 AM.


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

Content Relevant URLs by vBSEO 3.2.0