Visit Our UNIX and Linux User Community


Plz Help in sorting the data on date basis


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Plz Help in sorting the data on date basis
# 1  
Old 11-08-2013
Plz Help in sorting the data on date basis

I have file a.txt having below data

cat a.txt
Code:
01-MAY-13 2.38.11.00.100089 IN 4512 0000741881
01-JUN-13 2.38.11.00.100089 IN 1514 0000764631
01-NOV-13 2.38.11.00.100089 IN 1514 0000856571
01-NOV-13 2.38.15.00.100015 IN 300.32 0000856531
01-JUN-13 2.38.19.00.100000 IN 2698 0000764493
01-JUL-13 2.38.19.00.100000 IN 2850.14 0000768996
01-NOV-13 2.38.19.00.100000 IN 2698 0000856493

Code:
sort -n -k a.txt

but it is not working

i want to sort the above data on date basis and my output should be as below

Code:
01-MAY-13	2.38.11.00.100089	IN	4512	0000741881
01-JUN-13	2.38.19.00.100000	IN	2698	0000764493
01-JUN-13	2.38.11.00.100089	IN	1514	0000764631
01-JUL-13	2.38.19.00.100000	IN	2850.14	0000768996
01-NOV-13	2.38.19.00.100000	IN	2698	0000856493
01-NOV-13	2.38.11.00.100089	IN	1514	0000856571
01-NOV-13	2.38.15.00.100015	IN	300.32	0000856531

Please help

Thanks in advance.

Last edited by Don Cragun; 11-08-2013 at 08:01 AM.. Reason: Add CODE tags.
# 2  
Old 11-08-2013
Try

for considering only month

Code:
$ sort -t-  -k2M  file

01-MAY-13 2.38.11.00.100089 IN 4512 0000741881
01-JUN-13 2.38.11.00.100089 IN 1514 0000764631
01-JUN-13 2.38.19.00.100000 IN 2698 0000764493
01-JUL-13 2.38.19.00.100000 IN 2850.14 0000768996
01-NOV-13 2.38.11.00.100089 IN 1514 0000856571
01-NOV-13 2.38.15.00.100015 IN 300.32 0000856531
01-NOV-13 2.38.19.00.100000 IN 2698 0000856493

this considers day - mon - year
Code:
$ sort -t- -k3 -k2M -nk1  file


Last edited by Akshay Hegde; 11-08-2013 at 07:27 AM.. Reason: to add some more info
This User Gave Thanks to Akshay Hegde For This Post:
# 3  
Old 11-08-2013
Try

Code:
sort -t- -nk3 -k2M -nk1  file

This User Gave Thanks to pamu For This Post:
# 4  
Old 11-08-2013
@ranabhavish please use codetag for data also..
This User Gave Thanks to Akshay Hegde For This Post:
# 5  
Old 11-08-2013
This same discussion was also started and answered here.
Moderator's Comments:
Mod Comment Please do not post the same question in multiple forums; it fragments the responses and wastes time for those of us trying to help you.
# 6  
Old 11-08-2013
Ok, i will follow this next time, as i was new to this that's why this happened.
Thanks

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. 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

2. UNIX for Dummies Questions & Answers

Plz Help in sorting the data on date basis

I have file having below data 01-MAY-13 2.38.11.00.100089 IN 4512 0000741881 01-JUN-13 2.38.11.00.100089 IN 1514 0000764631 01-NOV-13 2.38.11.00.100089 IN 1514 0000856571 01-NOV-13 2.38.15.00.100015 IN 300.32 0000856531 01-JUN-13 2.38.19.00.100000 IN 2698 0000764493 01-JUL-13... (2 Replies)
Discussion started by: ranabhavish
2 Replies

3. Shell Programming and Scripting

Sorting data file by date and time

Hello. Sorting data file by date and time with the following issues: Date is in the following format m/d/yyyy, no leading zeros Time is in the following format h:m:s AM/PM, no leading zeros Any ideas on how to sort data when the above issues? Could the date/time be converted inline to... (5 Replies)
Discussion started by: JimBurns
5 Replies

4. 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

5. Shell Programming and Scripting

Group on the basis of common text in the square bracket and sorting

File A 99 >ac >ss >juk 70 >acb >defa 90 >ca 100 >aa >abc >bca 85 >cde 81 >ghi >ghij 87 >def >fgh <ijk 89 >fck >ghij >kill >aa The given output shud be 100 >aa >abc >bca 87 >def >fgh <ijk 89 >fck >ghij >kill >aa (2 Replies)
Discussion started by: cdfd123
2 Replies

6. Shell Programming and Scripting

send an e-mail on the date basis

one of the script is writing as fallow . certification authority - exprire on July 16, 2056 How to send an e-mail to an e-mail id say abc@gmail.com one month before the expire date. Thanks (1 Reply)
Discussion started by: nagendramv
1 Replies

7. UNIX and Linux Applications

Matlab (more generally: sorting data by date)

I'm not sure if this really belongs anywhere on this forum but my previous experiences on here have shown me that you guys are very helpful so I figure I may as well try. I have a bunch of large 2d arrays in matlab and each has a column for a date that each row corresponds to. The format is... (1 Reply)
Discussion started by: skray
1 Replies

8. Shell Programming and Scripting

sorting of files on the basis of timestamp

Hi, With the help of below script im able to get the count of all the .xml files but that count is not specific to a day ie its the total count of all .xml files what i want is specific to 1 day and that of every half an hr ie from 23 feb 2009 7 am till 23rd feb 2009 2300 am and from 07:00 to... (1 Reply)
Discussion started by: ss_ss
1 Replies

9. UNIX for Dummies Questions & Answers

Need Unix Terminal for practise on Rental basis ...plz help!

Hey Guys,, Have just got started with Unix , I need UNIX Terminal to practise commands. Does any website host such services ? Happy Holidays... (9 Replies)
Discussion started by: rrover1977
9 Replies

Featured Tech Videos