date(ddmmyyyy) sorting


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting date(ddmmyyyy) sorting
# 8  
Old 12-07-2011
@urfrnddpk: Seriously? Did that work? Can you post the output you're getting on your system?

This is what I'm getting:
Code:
$ echo "12319999\n01012013\n12312011\n01012011" |sort -k1.4 -k5
12319999\n01012013\n12312011\n01012011

My system is:
Code:
$ uname -a
Linux <host_name> 2.6.18-53.el5 #1 SMP Wed Oct 10 16:34:19 EDT 2007 x86_64 x86_64 x86_64 GNU/Linux

# 9  
Old 12-08-2011
Quote:
Originally Posted by curleb
Mileage may vary:

Code:
echo "12319999\n01012013\n12312011\n01012011" |sort -k1.4 -k5

if the input is(mmddyyyy) :
12012012
22112011
01122011

then it is not working fine. 12012012 should come either in first position or in last .

your logic is working fine in case of yyyymmdd format .

---------- Post updated at 01:40 PM ---------- Previous update was at 01:35 PM ----------

Quote:
Originally Posted by balajesuri
@urfrnddpk: Seriously? Did that work? Can you post the output you're getting on your system?

This is what I'm getting:
Code:
$ echo "12319999\n01012013\n12312011\n01012011" |sort -k1.4 -k5
12319999\n01012013\n12312011\n01012011

My system is:
Code:
$ uname -a
Linux <host_name> 2.6.18-53.el5 #1 SMP Wed Oct 10 16:34:19 EDT 2007 x86_64 x86_64 x86_64 GNU/Linux

hello

i am using HP UNIX and the output i am getting is :
01012011
12312011
01012013
12319999
but when i am trying a different input like :
echo "12012012\n01122011\n22112011"|sort -k1.4 -k5
the output is totally different
output is :
22112011
12012012
01122011

according to my requirment 12012012 should come either in first position or in last position ..
can you help please?
# 10  
Old 12-08-2011
@urfrnddpk: Is there anyway to tell if the input is in DDMMYYYY or MMDDYYYY? Or will your input be a mix of DDMMYYYY, MMDDYYYY and YYYYMMDD? If your input contains 01062011 and 04022011 can you think of a way to make the computer understand that it is 1st of June, 2011 and April 2nd, 2011.
# 11  
Old 12-08-2011
Quote:
Originally Posted by balajesuri
@urfrnddpk: Is there anyway to tell if the input is in DDMMYYYY or MMDDYYYY? Or will your input be a mix of DDMMYYYY, MMDDYYYY and YYYYMMDD? If your input contains 01062011 and 04022011 can you think of a way to make the computer understand that it is 1st of June, 2011 and April 2nd, 2011.
actually it is a mix of mmddyyyy and yyyymmdd. but somehow i can distinguish these two formats . the logic(-k1.4 -k5) is working fine in yyyymmdd format and am getting the latest date in the end of output .
but in ddmmyyyy the results are different .

and i don't know any such methode so that i can convert these date format into any another date format
# 12  
Old 12-08-2011
Ok. So assuming your input has only MMDDYYYY and YYYYMMDD, you can replace this:
Code:
y=`echo $x | cut -c7-8``echo $x | cut -c5-6``echo $x | cut -c1-4`

with this:
Code:
y=`echo $x | cut -c5-6``echo $x | cut -c7-8``echo $x | cut -c1-4`

And in the last line of script, use sort -nr ..... to reverse sort the output.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Command to check date format DDMMYYYY

Record: Record1|Record2|Record3|Record4|Record5|DATE1|DATE2 Need to Check DATE1 & DATE2 is in DDMMYYYY format in a file. records which not meet the date format DDMMYYYY extract to other file. (1 Reply)
Discussion started by: vivekn
1 Replies

2. UNIX for Dummies Questions & Answers

Sorting on fields for last date

Hi all, I have a file with a list of rpm's that have different dates. I am trying to just grab the latest rpm and install date, and discard the rest. The file has 1000's of entries all with different names and dates. I have tried sort -k on the file and I am not grabbing the info, ... (4 Replies)
Discussion started by: gartie
4 Replies

3. Shell Programming and Scripting

Sorting on date basis

I have file data.txt having below data cat data.txt 01-MAY-13 2.38.11.00.100089 IN 4512 0000741881 01-MAY-13 2.38.11.00.100089 IN 4512 0000741881 01-JUN-13 2.38.11.00.100089 FC 1514 0000764631 01-NOV-13 2.38.11.00.100089 FC 1514 0000856571 01-NOV-13 2.38.11.00.100089 IN 300.32... (1 Reply)
Discussion started by: ranabhavish
1 Replies

4. Shell Programming and Scripting

Sorting by date

I am trying to sort by two columns. The first column in an ID, the second is a date in the form yyyy-mm-dd. I need to sort by the ID column, then in ascending order for the date column (earliest date to most recent date compared to today). Input data: 012-abc 2012-04-25 ... (3 Replies)
Discussion started by: mollydog11
3 Replies

5. Shell Programming and Scripting

Sorting the data with date

Hi, PFB the data: C_Random_130417 Java_Random_130518 Perl_Random_120519 Perl_Random_120528 so the values are ending with year,i.e.,130417 i want to sort the values with date. i want the output like this: Perl_Random_120519 Perl_Random_120528 C_Random_130417 Java_Random_130518 can... (5 Replies)
Discussion started by: arindam guha
5 Replies

6. Shell Programming and Scripting

Date format to be changed from DDMMYYYY to YYYYMMDD

My requirement is:- there will be files at a location each day with the date format DDMMYYYY. Novawise_Activity_Call_Notes_04022013.txt Novawise_Activity_Inbound_04022013.txt Novawise_Activity_Inbound_05022013.txt Novawise_Activity_Call_Notes_05022013.txt... (8 Replies)
Discussion started by: djrulz123
8 Replies

7. UNIX for Dummies Questions & Answers

Sorting by date and time

Hi guys... I've been trying to do this for ages. Maybe you can help. I have log files like the examples below and I have grepped out certain lines from the files so that I can get an idea of who is logging on and how. So now I have the information in a new file but it is now in a different order... (7 Replies)
Discussion started by: padmundo
7 Replies

8. Shell Programming and Scripting

Date Sorting

Hi, I have a list of files that take on the format ABCDE_yymmdd and wish to sort them in ascending date order. I can't use the unix time stamp for the file as this could possibly be different from the date given in the file name. Does anyone know of any way this can be done using unix shell... (14 Replies)
Discussion started by: LiquidChild
14 Replies

9. UNIX for Dummies Questions & Answers

date sorting

Hi at all, I have to sort a log file on timestamp field. That's field is the third! a log file sample..... 1|EVTVOD-1-20060709_000614|2006/07/09-0:11:23|0.3.8 1|EVTVOD-1-20060709_000614|2006/07/09-0:11:16|0.3.8 1|EVTVOD-1-20060709_000614|2006/07/09-0:11:20|0.3.8... (3 Replies)
Discussion started by: nmilella
3 Replies

10. UNIX for Dummies Questions & Answers

sorting on date

I have a file where dates in the form mm/dd/yyyy is the first field. How do I sort the file by the date field? Thanks, Duckman (6 Replies)
Discussion started by: Duckman
6 Replies
Login or Register to Ask a Question