The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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 and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
convert date format YYYYMMDD to MM/DD/YYYY nasirgondal Shell Programming and Scripting 8 04-08-2009 10:56 AM
Perl script to extract last date field (yyyy/mm/dd) ganapati Shell Programming and Scripting 1 01-09-2009 12:31 PM
Change Date from dd-mmm-yyyy to mm/dd/yyyy stringzz Shell Programming and Scripting 9 09-15-2008 10:09 AM
Date Vadidation in YYYY-MM-DD itsmehihihi Shell Programming and Scripting 1 07-22-2007 09:22 PM
sed to display date in dd/mm/yyyy format sars Shell Programming and Scripting 2 02-15-2007 03:32 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 03-17-2009
pareshan pareshan is offline
Registered User
  
 

Join Date: Dec 2008
Posts: 24
converting the date field from dd/mm/yyyy to yyyy/mm/dd

How to convert the date field from dd/mm/yyyy to yyyy/mm/dd in unix
my script will generate text file which have two fields
one is date and another is name of the server for example this is sample date which I have to sort based on older to newer date the problem is when I found out sort will work good if i have date format in yyyy/mm/dd

So anyone can help me converting the format from dd/mm/yyyy to yyyy/mm/dd or sort as it is but it should be from older to newer one

11/14/2005 "labqaxm"
11/14/2006 "labqaxm"
11/29/2004 "amadeus"
11/29/2008 "amadeus"
11/29/2004 "betty"
11/29/2004 "dhprrn"
11/29/2009"flash"
11/29/2004 "wilma"
11/29/2004 "wilma"
11/29/2007 "dhprrn"
11/29/2007 "dhprrn"
11/29/2007 "dhprrn"
11/29/2007 "dhprrn"
11/29/2008"dhprrn"
11/29/2007 "dhprrn"
11/29/2006"dhprrn"
11/29/2007 "dhprrn"
11/29/2005"dhprrn"
11/29/2007 "dhprrn"
11/29/2007 "dhprrn"
11/29/2007 "dhprrn"
11/29/2000"dhprrn"
11/29/2007 "dhprrn"
11/29/2007 "dhprrn"
11/29/2010dhprrn"
11/29/2007 "dhprrn"
11/30/2010 "boesky"
11/30/2010 "boesky"

Thank you very much I will really appreciate any help
Im in trouble
  #2 (permalink)  
Old 03-17-2009
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,116
Have you tried searching these forums first?
  #3 (permalink)  
Old 03-17-2009
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,643
Code:
awk '{
      date=""
      date= substr($1,7,4)  substr($1,4,2) substr($1,1,2)
      print date, $0
    }' filename | sort -n |
    while read date rest
    do
        echo "$rest"
    done > newfile
  #4 (permalink)  
Old 03-17-2009
Goldorakk's Avatar
Goldorakk Goldorakk is offline
Registered User
  
 

Join Date: Feb 2009
Location: France
Posts: 43
Code:
#!/bin/ksh

while read line
do
        echo $line | cut -c1-10 | sed -e 's/\// /g' | read D M Y
        echo $Y/$M/$D$(echo $line | cut -c11-)

done < infile
  #5 (permalink)  
Old 03-17-2009
cfajohnson's Avatar
cfajohnson cfajohnson is offline Forum Advisor  
Shell programmer, author
  
 

Join Date: Mar 2007
Location: Toronto, Canada
Posts: 2,315
Code:
sort -n -k3,3 -k2,2 -k1,1 file
Sponsored Links
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 07:54 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
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