Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Plz Help in sorting the data on date basis Post 302872283 by Don Cragun on Friday 8th of November 2013 05:03:03 AM
Old 11-08-2013
If the sort utility on your system provides a -M option (to sort month names), sort can reorder lines the way you want, but it won't change spaces to tabs:
Code:
sort -k1.8,1 -k 1.4M,1.6 -k1,1.2 -k5 file

If you need to change the spaces to tabs, add tr in a pipeline:
Code:
sort -k1.8,1 -k 1.4M,1.6 -k1,1.2 -k5 file | tr ' ' '\t'

If your sort doesn't support the -M option, you'll have to preprocess the data to convert the month names to numbers, sort the results, and convert the numbers back to month names.
This User Gave Thanks to Don Cragun For This Post:
 

9 More Discussions You Might Find Interesting

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

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

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

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

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

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

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

8. Shell Programming and Scripting

Plz Help in sorting the data on date basis

I have file a.txt having below data cat a.txt 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... (5 Replies)
Discussion started by: ranabhavish
5 Replies

9. 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
sort(1) 						      General Commands Manual							   sort(1)

Name
       sort - sort file data

Syntax
       sort [options] [-k keydef] [+pos1[-pos2]] [file...]

Description
       The  command  sorts  lines  of  all the named files together and writes the result on the standard output.  The name `-' means the standard
       input.  If no input files are named, the standard input is sorted.

Options
       The default sort key is an entire line.	Default ordering is lexicographic by  bytes  in  machine  collating  sequence.	 The  ordering	is
       affected globally by the following options, one or more of which may appear.

       -b	   Ignores leading blanks (spaces and tabs) in field comparisons.

       -d	   Sorts data according to dictionary ordering:  letters, digits, and blanks only.

       -f	   Folds uppercase to lowercase while sorting.

       -i	   Ignore characters outside the ASCII range 040-0176 in nonnumeric comparisons.

       -k keydef   The	keydefargument	is  a key field definition. The format is field_start, [field_end] [type], where field_start and field_end
		   are the definition of the restricted search key, and type is a modifier from the option list [bdfinr]. These modifiers have the
		   functionality, for this key only, that their command line counter-parts have for the entire record.

       -n	   Sorts fields with numbers numerically.  An initial numeric string, consisting of optional blanks, optional minus sign, and zero
		   or more digits with optional decimal point, is sorted by arithmetic value.  (Note that -0 is taken to be equal to 0.)  Option n
		   implies option b.

       -r	   Reverses the sense of comparisons.

       -tx	   Uses specified character as field separator.

       The  notation  +pos1 -pos2 restricts a sort key to a field beginning at pos1 and ending just before pos2.  Pos1 and pos2 each have the form
       m.n, optionally followed by one or more of the options bdfinr, where m tells a number of fields to skip from the beginning of the line  and
       n tells a number of characters to skip further.	If any options are present they override all the global ordering options for this key.	If
       the b option is in effect n is counted from the first nonblank in the field; b is attached independently to pos2.  A missing .n means .0; a
       missing	-pos2  means the end of the line.  Under the -tx option, fields are strings separated by x; otherwise fields are nonempty nonblank
       strings separated by blanks.

       When there are multiple sort keys, later keys are compared only after all earlier keys compare equal.  Lines that otherwise  compare  equal
       are ordered with all bytes significant.

       These are additional options:

       -c	   Checks sorting order and displays output only if out of order.

       -m	   Merges previously sorted data.

       -o name	   Uses specified file as output file.	This file may be the same as one of the inputs.

       -T dir	   Uses specified directory to build temporary files.

       -u	   Suppresses all duplicate entries.  Ignored bytes and bytes outside keys do not participate in this comparison.

Examples
       Print in alphabetical order all the unique spellings in a list of words.  Capitalized words differ from uncapitalized.
	       sort -u +0f +0 list

       Print the password file, sorted by user id number (the 3rd colon-separated field).
	       sort -t: +2n /etc/passwd

       Print the first instance of each month in an already sorted file of (month day) entries.  The options -um with just one input file make the
       choice of a unique representative from a set of equal lines predictable.
	       sort -um +0 -1 dates

Restrictions
       Very long lines are silently truncated.

Diagnostics
       Comments and exits with nonzero status for various trouble conditions and for disorder discovered under option c.

Files
       /usr/tmp/stm*, /tmp/*	first and second tries for temporary files

See Also
       comm(1), join(1), rev(1), uniq(1)

																	   sort(1)
All times are GMT -4. The time now is 08:24 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy