Sponsored Content
Full Discussion: Sort cmd to get GROUP BY?
Top Forums UNIX for Dummies Questions & Answers Sort cmd to get GROUP BY? Post 302247362 by joeyg on Wednesday 15th of October 2008 01:43:29 PM
Old 10-15-2008
Hammer & Screwdriver I think you need to experiment with full key definitions

Without seeing the data, I can only simulate. Perhaps the following example will help illustrate:

sample file
Code:
> cat file99
joe:1:alpha:4:5
jim:4:beta:16:9
bette:2:comma:99:0
dennis:3:per:12:12
harry:2:comma:12:13
olivia:1:beta:4:4

Trying to sort based on key field 3 then field 2. Field 3 should put the two beta people together and then the second field should put olivia before jim based on the 1 and 4 in their records. This did not happen.
Code:
> sort -t: -k3 -k2 file99
joe:1:alpha:4:5
jim:4:beta:16:9
olivia:1:beta:4:4
harry:2:comma:12:13
bette:2:comma:99:0
dennis:3:per:12:12

I then tried by putting explicit field definitions (start and end locations). So I am sorting on the first 3 characters of field 3 to get the beta people together. Then sort on field 2 - getting olivia before jim.
Code:
> sort -t: -k3.1,3.3 -k2 file99
joe:1:alpha:4:5
olivia:1:beta:4:4
jim:4:beta:16:9
harry:2:comma:12:13
bette:2:comma:99:0
dennis:3:per:12:12

 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

man <cmd> >> cmd.txt

I've noticed most of my postings here are because of syntax errors. So I want to begin compiling a large txt file that contains all the "man <cmd>" of the commands I most have problems with. I ran a "man nawk >> nawk.txt" but it included a header/footer on each "page". Anyone know how I'd be... (6 Replies)
Discussion started by: yongho
6 Replies

2. Shell Programming and Scripting

Sort, group rows

I wrote script in bash which generates this report: User1,admin,rep,User2,shell,path1,x1,r1 User2,admin,rep,User7,shell,path1,x1,r1 User3,admin,rep,User4,shell,path1,x1,r1 User4,admin,rep,User3,shell,path1,x1,r1 User5,admin,rep,User1,shell,path1,x1,r1 User6,admin,rep,User5,shell,path1,x1,r1... (6 Replies)
Discussion started by: patrykxes
6 Replies

3. Shell Programming and Scripting

awk - sort, then print the high value for each group

Hi @ all I'm trying to achive to this problem, I've a 2-column composed file as the following: 192.168.1.2 2 192.168.1.3 12 192.168.1.2 4 192.168.1.4 3 cpc1-swan1-2-3-cust123.swan.cable.ntl.com 4 192.168.1.3 5 192.168.1.2 10 192.168.1.4 8... (8 Replies)
Discussion started by: m4rco-
8 Replies

4. UNIX for Dummies Questions & Answers

sort group of n lines base on pattern in first line

I have record having 10 fields and each field being printed on a new line, first line cotains name of exchange, 2nd line stock name, third line stock price, etc etc... now i want to retrieve data only for a particular exchanged and that too only 2nd and 3rd row info... NSE RNRL 70 12 1... (1 Reply)
Discussion started by: manishma71
1 Replies

5. Shell Programming and Scripting

AWK or KSH : Sort, Group and extract from 3 files

Hi, I've the following two CSV files: File1.csv File2.csv Class,Student# Student#,Marks 1001,6001 6002,50 1001,6002 6001,60 1002,7000 ... (3 Replies)
Discussion started by: Matrix2682
3 Replies

6. Shell Programming and Scripting

Sort the file contents in each group....print the group title as well

I've this file and need to sort the data in each group File would look like this ... cat file1.txt Reason : ABC 12345-0023 32123-5400 32442-5333 Reason : DEF 42523-3453 23345-3311 Reason : HIJ 454553-0001 I would like to sort each group on the last 4 fileds and print them... (11 Replies)
Discussion started by: prash184u
11 Replies

7. Shell Programming and Scripting

Unix cmd prompt how to get old cmd run?

Hi, I am using SunOS I want to serch my previous command from unix prompt (like on AIX we can search by ESC -k) how to get in SunOs urgent help require. (10 Replies)
Discussion started by: RahulJoshi
10 Replies

8. Shell Programming and Scripting

Sort Data by Group !

Hello, I have a file and i want to sort by third column and extract the three top lines of each group, it is determined by the second column (144, 89, 55, etc). Could you please help me with the appropiate awk shell script XLY-XLP 144 0.592772 XLY-XLE 144 0.798121 ... (3 Replies)
Discussion started by: csierra
3 Replies

9. Shell Programming and Scripting

Perl open(CMD, "cmd |"); buffering problem..

Hello, There's a third-party application's command that shows the application's status like "tail -f verybusy.log". When use the command, the output comes every 1-sec. but when it goes in a script below the output comes every 8-sec...What is the problem and how can I fix it? open(CMD,... (2 Replies)
Discussion started by: Shawn, Lee
2 Replies

10. UNIX for Advanced & Expert Users

Group/Sort logs by thread number

Hello Experts, For the following sample log, can you tell me how I can sort it or group it by thread number. To be specific, I just want to group them together so that its easy to analyize. Thanks. 2012-08-17 00:00:06,369 INFO ExecuteThread: '33' for queue:... (2 Replies)
Discussion started by: samjna
2 Replies
ALTER 
GROUP(7) PostgreSQL 9.2.7 Documentation ALTER GROUP(7) NAME
ALTER_GROUP - change role name or membership SYNOPSIS
ALTER GROUP group_name ADD USER user_name [, ... ] ALTER GROUP group_name DROP USER user_name [, ... ] ALTER GROUP group_name RENAME TO new_name DESCRIPTION
ALTER GROUP changes the attributes of a user group. This is an obsolete command, though still accepted for backwards compatibility, because groups (and users too) have been superseded by the more general concept of roles. The first two variants add users to a group or remove them from a group. (Any role can play the part of either a "user" or a "group" for this purpose.) These variants are effectively equivalent to granting or revoking membership in the role named as the "group"; so the preferred way to do this is to use GRANT(7) or REVOKE(7). The third variant changes the name of the group. This is exactly equivalent to renaming the role with ALTER ROLE (ALTER_ROLE(7)). PARAMETERS
group_name The name of the group (role) to modify. user_name Users (roles) that are to be added to or removed from the group. The users must already exist; ALTER GROUP does not create or drop users. new_name The new name of the group. EXAMPLES
Add users to a group: ALTER GROUP staff ADD USER karl, john; Remove a user from a group: ALTER GROUP workers DROP USER beth; COMPATIBILITY
There is no ALTER GROUP statement in the SQL standard. SEE ALSO
GRANT(7), REVOKE(7), ALTER ROLE (ALTER_ROLE(7)) PostgreSQL 9.2.7 2014-02-17 ALTER GROUP(7)
All times are GMT -4. The time now is 02:40 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy