sort for timestamp information-YYYY-MM-DD HH:MM:SS


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting sort for timestamp information-YYYY-MM-DD HH:MM:SS
# 1  
Old 06-05-2009
sort for timestamp information-YYYY-MM-DD HH:MM:SS

Dear all,

Please advice how do I sort a file based on timestamp information. I want to sort the second column in asc/desc order which has timestamp information in format YYYY-MM-DD HH:MM:SS

Example
File - Input.txt contains
cat ss.txt
100|2009-03-30 11:38:43
141|2009-06-01 12:12:01
200|2009-06-01 12:10:01
200|2009-06-01 12:11:01

When i run command below, I get result as
sort -t'|' -k2,n Input.txt
100|2009-03-30 11:38:43
141|2009-06-01 12:12:01
200|2009-06-01 12:10:01
200|2009-06-01 12:11:01

But the correct expected output [ which means HH:MM:SS part should also be sorted] is
100|2009-03-30 11:38:43
141|2009-06-01 12:10:01
200|2009-06-01 12:11:01
200|2009-06-01 12:12:01

How do I get this expected output, please advice

Regards,
SUresh
# 2  
Old 06-05-2009
Are you using some alias or LC_ALL setting? Works as advertised for me.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Find files and sort by timestamp

Used below command to get list of files sorted by timestamp find -L . -type f -name '*dat*' | xargs ls -ltrg I want to get only the filenames so I tried adding basename but it doenst work , can some one advise on how to get only file name (1 Reply)
Discussion started by: lalitpct
1 Replies

2. Shell Programming and Scripting

Convert date in dd mm yyyy format to UNIX timestamp

Hello All, I have a date in DD/MM/YYYY format. I am trying to convert this into unix timestamp. I have tried following: date -d $mydate +%s where mydate = 23/12/2016 00:00:00 I am getting following error: date: extra operand `+%s' Try `date --help' for more information. ... (1 Reply)
Discussion started by: angshuman
1 Replies

3. Shell Programming and Scripting

Solaris 5.10 CPU Information With Timestamp

Hi, In Solaris 5.10, can I run a command or a small script that will output CPU% user, system, wait and idle (The output from iostat or vmstat) along with a date/timestamp. The date/timestamp can be in any format that is easy to understand. I intend to use crontab to call the script once... (2 Replies)
Discussion started by: QZ1
2 Replies

4. Shell Programming and Scripting

Sort on mm/dd/yyyy csv

I have the following csv data that I would like to sort on the 4th field by date from oldest to newest. data: ,,,02/06/2012,Carry H,Add,Add,Sys_RTH,111.222.333.777 4/7/12,,,03/03/2013,Parry H,Add,Add,Sys_RTH,111.222.333.776 ,,,12/06/2012,Harry H,Add,Add,Sys_RTH,111.222.333.778... (3 Replies)
Discussion started by: wbrunc
3 Replies

5. Programming

Sort the files on their name and then the timestamp using Perl

Hi All, I am new to Perl. I have a scenario to code. In a folder I have number of files and they will start with P01 or P02 or P03 and so on..I have to sort them on name first and then on time stamp. Ex. File name timestamp P01_file1.txt 1PM P02_file1.txt 1AM P01_file2.txt 2PM... (12 Replies)
Discussion started by: unankix
12 Replies

6. Shell Programming and Scripting

Converting date DD MM YYYY to DD MON YYYY

Hello, I am writing a script that parses different logs and produces one. In the source files, the date is in DD MM YYYY HH24:MI:SS format. In the output, it should be in DD MON YYY HH24:MI:SS (ie 25 Jan 2010 16:10:10) To extract the dates, I am using shell substrings, i.e.: read line ... (4 Replies)
Discussion started by: Adamm
4 Replies

7. UNIX for Dummies Questions & Answers

Sort field by date mm/dd/yyyy

Hello Group, I would like to sort the below file by date (first year then month and day) and I used the following command but it does not work sort -n -t"/" -k3 -k1 -k2 "sample original file" 12/28/2009,1.0353 12/31/2009,1.0357 12/30/2009,1.0364 12/29/2009,1.0366 12/24/2009,1.0386... (6 Replies)
Discussion started by: csierra
6 Replies

8. Shell Programming and Scripting

Sed: zero-padding dates (or: convert d/m/yyyy to dd/mm/yyyy)

Hi all I have some pipe-separated data in the form: 5/12/2008 00:00:00|31/1/2009 00:00:00|SOMESTUFF|OTHERSTUFF 12/31/2008 00:00:00|15/1/2009 00:00:00|MORESTUFF|REMAININGSTUFF 1/1/1023 00:00:00|16/5/2047 00:00:00|THEREST|YETMORE I need to zero-pad the single-digit days and months, using... (3 Replies)
Discussion started by: jgrogan
3 Replies

9. Shell Programming and Scripting

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... (4 Replies)
Discussion started by: pareshan
4 Replies

10. Shell Programming and Scripting

Change Date from dd-mmm-yyyy to mm/dd/yyyy

I want to change a date from format dd-mmm-yyyy to mm/dd/yyyy. Is there a way to do this with sed or do you have to write a case statement to convert JAN to 01? Thanks (9 Replies)
Discussion started by: stringzz
9 Replies
Login or Register to Ask a Question