The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



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 !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
reformat date, awk and sed mondrar Shell Programming and Scripting 5 06-05-2008 04:08 PM
help reformat data with awk climbak Shell Programming and Scripting 4 05-30-2008 03:17 PM
how to reformat a hard disk mr_balodoy SUN Solaris 14 08-22-2007 03:29 AM
Reformat Crontab file alnita Shell Programming and Scripting 1 04-11-2007 03:28 AM
reformat the file CamTu Shell Programming and Scripting 3 03-09-2005 05:01 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 04-24-2006
F-1 F-1 is offline
Registered User
  
 

Join Date: Apr 2006
Posts: 4
Question Date Reformat

Hello,

I have a .CSV file with 10+ datetime columns. The way the data is stored
in these columns are -

4/4/2006 3:45:30 PM

I want the single digits to be left padded with a zero so the above looks like

04/04/2006 03:45:30 PM

As the dates and times are different throughout the file manually changing
it in the file with a find and replace is not considered.

Any function/command to achieve this will be appreciated. Thanks.

Rgds,
F1
  #2 (permalink)  
Old 04-25-2006
Ygor's Avatar
Ygor Ygor is offline Forum Staff  
Moderator
  
 

Join Date: Oct 2003
Location: -31.96,115.84
Posts: 1,409
This is GNU sed, and not thoroughly tested...
Code:
$ echo 'field1,4/4/2006 3:45:30 PM,f3,4,etc'>file1
$ sed -e :a -e 's!\([^0-9]\)\([0-9]\)\([/:]\)!\10\2\3!;ta' file1
field1,04/04/2006 03:45:30 PM,f3,4,etc

  #3 (permalink)  
Old 04-25-2006
F-1 F-1 is offline
Registered User
  
 

Join Date: Apr 2006
Posts: 4
Thanks YGOR

This solution helped. Thanks mate. Much appreciated.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 05:52 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0