Sponsored Content
Top Forums UNIX for Advanced & Expert Users sorting data based on multi columns Post 302107232 by sumeet on Thursday 15th of February 2007 10:25:27 AM
Old 02-15-2007
sorting data based on multi columns

Hi all

I have data in following format:

CSCH74,2007,1,09103,15
CSCH74,2007,10,09103,0
CSCH74,2007,11,09103,0
CSCH74,2007,12,09103,0
CSCH74,2007,2,09103,15
CSCH74,2007,3,09103,194
CSCH74,2007,4,09103,115
CSCH74,2007,5,09103,66
CSCH74,2007,6,09103,0
CSCH74,2007,7,09103,0
CSCH74,2007,8,09103,0
CSCH74,2007,9,09103,0
CSCS74,2007,1,09103,142
CSCS74,2007,10,09103,0
CSCS74,2007,11,09103,0
CSCS74,2007,12,09103,0
CSCS74,2007,2,09103,1224
CSCS74,2007,3,09103,1332
CSCS74,2007,4,09103,1169
CSCS74,2007,5,09103,195
CSCS74,2007,6,09103,0
CSCS74,2007,7,09103,0
CSCS74,2007,8,09103,0
CSCS74,2007,9,09103,0

I want to sort it so that output is ( basically sort on column1 and 3)

CSCH74,2007,1,09103,15
CSCH74,2007,2,09103,15
CSCH74,2007,3,09103,194
CSCH74,2007,4,09103,115
CSCH74,2007,5,09103,66
CSCH74,2007,6,09103,0
CSCH74,2007,7,09103,0
CSCH74,2007,8,09103,0
CSCH74,2007,9,09103,0
CSCH74,2007,10,09103,0
CSCH74,2007,11,09103,0
CSCH74,2007,12,09103,0
CSCS74,2007,1,09103,142
CSCS74,2007,2,09103,1224
CSCS74,2007,3,09103,1332
CSCS74,2007,4,09103,1169
CSCS74,2007,5,09103,195
CSCS74,2007,6,09103,0
CSCS74,2007,7,09103,0
CSCS74,2007,8,09103,0
CSCS74,2007,9,09103,0
CSCS74,2007,10,09103,0
CSCS74,2007,11,09103,0
CSCS74,2007,12,09103,0

I have tried :

sort -t, +2 -3 +0 -1 file
sort -t, -k3,3 n -k1,1 file
sort -t"," -k3,3 n -k1,1 file

result is not what I wanted

CSCH74,2007,1,09103,15
CSCS74,2007,1,09103,142
CSCX74,2007,1,09103,28
CSYH74,2007,1,09103,57
CSYS74,2007,1,09103,165
CSYX74,2007,1,09103,11
D13H41,2007,1,08475,5
D13H42,2007,1,08475,43
D13H62,2007,1,08475,1
D13H81,2007,1,08475,12
D13L41,2007,1,08475,0


sort -t, -k1,1 -k3,3 n file
sort -t"," -k1,1 -k3,3 n file
sort -t"," -k 1,1 -k 3,3 n file

for all the above command the output is same as input file with statement cannot open 'n' and in last case cannot open -k 3,3 and n.

sort -t, -k1,1 -k3,3 -n file (comes up with usage of sort command)


nothing seems to work. any help from Unix Gurus is appreciated.

Thanks
Sumeet
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Sorting based on columns

Hi, I want a list of entries in 3 space delimited columns. I want to sort entries based on the very first column. Rows can't be changed. For example: If I have... Abc Abc Acc Bca Bda Bdd Cab Cab Cbc Dbc Dca Dda Abc Abc Acc the output should be... Abc Abc Acc Abc Abc Acc Bca... (7 Replies)
Discussion started by: MobileUser
7 Replies

2. Shell Programming and Scripting

sorting file based on two or more columns

Hi gang. I'm using a unix/mac system and i'm trying to sort a file (more than 1,000,000 lines). chr1 100000965 100001001 - chr1 100002155 100002191 + chr1 100002165 100002201 + chr1 100002525 100002561 - chr1 10000364 ... (2 Replies)
Discussion started by: labrazil
2 Replies

3. Shell Programming and Scripting

Sorting based on Multiple columns

Hi, I have a requirement whereby I have to sort a flat file based on Multiple Columns (similar to ORDER BY Clause of Oracle). I am getting 10 columns in the flat file and I want the file to be sorted on 1st, 3rd, 4th, 7th and 9th columns in ascending order. The flat file is pipe seperated. Any... (15 Replies)
Discussion started by: dharmesht
15 Replies

4. Shell Programming and Scripting

How to convert 2 column data into multiple columns based on a keyword in a row??

Hi Friends I have the following input data in 2 columns. SNo 1 I1 Value I2 Value I3 Value SNo 2 I4 Value I5 Value I6 Value I7 Value SNo 3 I8 Value I9 Value ............... ................ SNo N (1 Reply)
Discussion started by: ks_reddy
1 Replies

5. Shell Programming and Scripting

sorting multi dimensional array

Hi there, Can someone let me know how to sort the 2 dimensional array below by column 1 then by column 2? 22 55 2222 2230 33 66 44 58 222 240 11 25 22 60 33 45 output: 11 25 22 55 22 60 33 45 33 66 44 58 (6 Replies)
Discussion started by: phoeberunner
6 Replies

6. UNIX for Dummies Questions & Answers

Sorting data in file based on field in another file

Hi, I have two files, one of which I would like to sort based on the order of the data in the second. I would like to do this using a simple unix statement. My two files as follows: File 1: 12345 1 2 2 2 0 0 12349 0 0 2 2 1 2 12350 1 2 1 2 2 2 . . . File2: 12350... (3 Replies)
Discussion started by: kasan0
3 Replies

7. Shell Programming and Scripting

Awk based script to find the median of all individual columns in a data file

Hi All, I have some data like below. Step1,Param1,Param2,Param3 1,2,3,4 2,3,4,5 2,4,5,6 3,0,1,2 3,0,0,0 3,2,1,3 ........ so on Where I need to find the median(arithmetic) of each column from Param1...to..Param3 for each set of Step1 values. (Sort each specific column, if the... (5 Replies)
Discussion started by: ks_reddy
5 Replies

8. Shell Programming and Scripting

awk based script to find the average of all the columns in a data file

Hi All, I need the modification for the below mentioned code (found in one more post https://www.unix.com/shell-programming-scripting/27161-script-generate-average-values.html) to find the average values for all the columns(but for a specific rows) and print the averages side by side. I have... (4 Replies)
Discussion started by: ks_reddy
4 Replies

9. Shell Programming and Scripting

Multi line sorting in Linux

I have log files with following format - YYYY/MM/DD HH:mm:ss.msec|field2|filed3| log message Now the message itself can be multi line message containing new line character. for e.g. 2013/02/05 15:33:12.234|abc|xyz| This is first single line message. 2013/02/05 15:33:12.786|abc|xyz| This... (6 Replies)
Discussion started by: gini32
6 Replies

10. Shell Programming and Scripting

Split multi columns line to 2 columns

I have data like this 1 a,b,c 2 a,c 3 b,d 4 e,f would like convert like this 1 a 1 b 1 c 2 a 2 c 3 b 3 d 4 e 4 f Please help me out (4 Replies)
Discussion started by: jhonnyrip
4 Replies
Atompub::DateTime(3pm)					User Contributed Perl Documentation				    Atompub::DateTime(3pm)

NAME
Atompub::DateTime - A date and time object for the Atom Publishing Protocol SYNOPSIS
# assuming the local timezone is JST (+09:00) use Atompub::DateTime qw(datetime); $dt = datetime; # current time $dt = datetime(DateTime->new); $dt = datetime(1167609600); # UTC epoch value $dt = datetime('20070101090000'); $dt = datetime('2007-01-01 09:00:00'); $dt = datetime('2007-01-01 00:00:00Z'); $dt = datetime('2007-01-01T09:00:00+09:00'); $dt = datetime('2007-01-01T00:00:00Z'); $dt = datetime('Mon, 01 Jan 2007 00:00:00 GMT'); $dt->epoch; # 1167609600 (UTC epoch value) $dt->iso; # 2007-01-01 09:00:00 (in localtime) $dt->isoz; # 2007-01-01 00:00:00Z $dt->w3c; # 2007-01-01T09:00:00+09:00 $dt->w3cz; # 2007-01-01T00:00:00Z $dt->str; # Mon, 01 Jan 2007 00:00:00 GMT my $dt2 = datetime($dt); # copy $dt == $dt2; # compare "$dt"; # $dt->w3c $dt->dt; # DateTime object METHODS
Atompub::DateTime->new([ $str ]) Returns a datetime object representing the time $str. If the function is called without an argument, it will use the current time. datetime([ $str ]) An alias for Atompub::DateTime->new $datetime->epoch Returns UTC epoch value. 1167609600 $datetime->iso Returns a "YYYY-MM-DD hh:mm:ss"-formatted string representing time in the local time zone. 2007-01-01 09:00:00 $datetime->isoz Returns a "YYYY-MM-DD hh:mm:ssZ"-formatted string representing Universal Time. 2007-01-01 00:00:00Z $datetime->w3c Returns a "YYYY-MM-DDThh:mm:ssTZ"-formatted string (W3C DateTime Format) representing time in the local time zone. 2007-01-01T09:00:00+09:00 $datetime->w3cz Returns a "YYYY-MM-DDThh:mm:ssZ"-formatted string (W3C DateTime Format) representing Universal Time. 2007-01-01T00:00:00Z $datetime->str Returns a human readable representation. Mon, 01 Jan 2007 00:00:00 GMT $datetime->dt An accessor for the internal DateTime object. $datetime->tz An accessor for the internal DateTime::TimeZone object. $datetime->fmt An accessor for the internal DateTime::Format object. INTERNAL INTERFACES
$datetime->init $datetime->_parse_timestamp SEE ALSO
Atompub AUTHOR
Takeru INOUE, <takeru.inoue _ gmail.com> LICENCE AND COPYRIGHT
Copyright (c) 2007, Takeru INOUE "<takeru.inoue _ gmail.com>". All rights reserved. This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See perlartistic. DISCLAIMER OF WARRANTY
BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR, OR CORRECTION. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENCE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE SOFTWARE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. perl v5.14.2 2011-04-30 Atompub::DateTime(3pm)
All times are GMT -4. The time now is 01:36 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy