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
read from a file and calculate values for a specified field lucho_1 Shell Programming and Scripting 3 03-11-2008 07:24 PM
how to sort paragraphs by date within a file nabmufti Shell Programming and Scripting 1 02-13-2008 05:33 PM
loop through the directory for files and sort by date and process the first file dsdev_123 AIX 1 01-30-2008 05:31 PM
sort a file by date using perl esham Shell Programming and Scripting 4 04-14-2005 01:04 PM

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

Join Date: Oct 2007
Posts: 64
How to sort a field in a file having date values

Hi All,

I am having a pipe delimited file .In this file the 3rd column is having date values.I need to get the min date and max date from that file.

I have used
cut -d '|' test.dat -f 3|sort -u

But it is not sorting the date .How to sort the date column using unix commands

Thanks
Deepak
  #2 (permalink)  
Old 06-04-2008
zaxxon's Avatar
zaxxon zaxxon is offline Forum Staff  
Moderator
  
 

Join Date: Sep 2007
Location: Germany
Posts: 2,259
Show us some lines of your delimeted file, please.
  #3 (permalink)  
Old 06-04-2008
risshanth risshanth is offline
Registered User
  
 

Join Date: Oct 2007
Posts: 64
I have used a small file for testing

A line in the file looks like thsi
deepak|55445|12-02-2008|alappuzha
  #4 (permalink)  
Old 06-04-2008
ripat ripat is offline Forum Advisor  
Registered User
  
 

Join Date: Oct 2006
Location: Belgium
Posts: 438
The problem with your file is that the date is not ISO i.e. it is not sortable as it is. You have to split it and sort it first on the YYYY, then on MM and, finaly on DD. That's exactly what the following command does. It sorts on the 3rd field from character 7 to character 10 then on char. 4 to 5 etc...

Code:
sort -u -t"|" -k 3.7,3.10n -k 3.4,3.5n -k 3.1,3.2n file

Last edited by ripat; 06-04-2008 at 04:19 AM..
  #5 (permalink)  
Old 06-04-2008
risshanth risshanth is offline
Registered User
  
 

Join Date: Oct 2007
Posts: 64
Thanks a lot ...
Sponsored Links
Closed Thread

Bookmarks

Tags
unix commands

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 12:53 PM.


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