Sponsored Content
Full Discussion: Group by in UNIX
Top Forums Shell Programming and Scripting Group by in UNIX Post 302938657 by zozoo on Wednesday 18th of March 2015 09:08:38 AM
Old 03-18-2015
Quote:
Originally Posted by RudiC
Show us your attempts. What stops you from printing the lines with respective groups' max?
Code:
have tried below

$ cat sample
xxx,1,100
yyy,2,,200
zzz,1,3000
eeee,1,200
ttttt,2,500
zzz,2,123
xyxy,3,1000
$ awk -F, '{if (a[$2]< $3)a[$2]=$3;}END{for(i in a){print i,a[i];}}' sample
1 3000
2 500
3 1000

I also want to print name of each entity with max value along with dep and sal

---------- Post updated at 06:38 PM ---------- Previous update was at 06:29 PM ----------

if have to to same thing in sql it would be and data isin table say temp_tbl

Code:
select name,dep,sal from temp_tbl where(dep,sal) in ( select dep,max(sal)from temp_tbl group by dep)

 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

how to define permission of unix group

While logged on as root, I created a user 'usera' I also created a group called 'groupa' I need to modify the permission of the user i created to not have root privileges. I also need to change groupa to be in 'others' please help! thanks, nieves (3 Replies)
Discussion started by: mncapara
3 Replies

2. UNIX for Dummies Questions & Answers

listing members of a unix group

I know there is a "groups" command to list the groups a user belongs to, but how about the opposite? Is there a standard command to find out which users belong to a particular group? (2 Replies)
Discussion started by: ovaska
2 Replies

3. Solaris

unix group file limitation

Does anyone know how to get around the unix group file limitation whereby you have a limit of 1024 characters when adding users to a unix group? (3 Replies)
Discussion started by: asmillie
3 Replies

4. Shell Programming and Scripting

Achieving group by logic via Unix

HI friends, select count(*),country_code from employees_table group by country_code having com_country_code in ("US","UK") CAn we have an equivalent command in Unix to achieve this Thanks in advance Suresh (5 Replies)
Discussion started by: sureshg_sampat
5 Replies

5. Shell Programming and Scripting

create group in unix

Hi, I want to create group in unix. what is the command? how to create a group and add a user into that group? Thanks in advance (2 Replies)
Discussion started by: senthil_is
2 Replies

6. UNIX for Dummies Questions & Answers

Portland UNIX student group

In CS140 .... I am having a very hard time with lab 4. I am wondering if we could put together a study group in portland. This could help all of us. Post here and I will PM you my # and we can set it up over the phone. (0 Replies)
Discussion started by: aeamacman
0 Replies

7. Shell Programming and Scripting

Group By in Unix

Hi, I have file with Header Data and trailer records Head|currentdate|EOF Data|AAA|BBB|CCC|DDD|EEE|Source1 Data|AAA|BBB|CCC|DDD|EEE|Source1 Data|AAA|BBB|CCC|DDD|EEE|Source2 Data|AAA|BBB|CCC|DDD|EEE|Source2 Data|AAA|BBB|CCC|DDD|EEE|Source2 End|rec|EOF Now I need the count of only... (3 Replies)
Discussion started by: magesh_bala
3 Replies

8. Cybersecurity

UNIX group id

How to add a user to the existing user account of a solarise server? In our solarise server we hav a acc in the name telecom ,now how to add a new user to teleco acc so that he can login in to server through telecom acc. Thanks to help (4 Replies)
Discussion started by: kkalyan
4 Replies

9. UNIX for Advanced & Expert Users

Adding UNIX user to a group

Hi, I am new to unix. I am facing access permission issue I want to access path /app/compress from a user "test" but getting permission denied error This path exist in "Main" user So after some googling i came to know we need to add "test" user in "main" group so path /app/compress ... (7 Replies)
Discussion started by: sv0081493
7 Replies

10. Shell Programming and Scripting

To group records in the file in UNIX

Hi All, I am using RHEL 6.9. I got a requirement to group the records in a file.The file content as shown below. #### FAILED JOBS IN XXX ##### 1> ABCD failed in the project XXX 2> HJK Job is in compiled state in the project XXX 3> ILKD failed in the project XXX 4> DFG failed in the... (5 Replies)
Discussion started by: ginrkf
5 Replies
explain_readdir(3)					     Library Functions Manual						explain_readdir(3)

NAME
explain_readdir - explain readdir(2) errors SYNOPSIS
#include <libexplain/readdir.h> const char *explain_readdir(DIR *dir); const char *explain_errno_readdir(int errnum, DIR *dir); void explain_message_readdir(char *message, int message_size, DIR *dir); void explain_message_errno_readdir(char *message, int message_size, int errnum, DIR *dir); DESCRIPTION
These functions may be used to obtain explanations for errors returned by the readdir(2) system call. explain_readdir const char *explain_readdir(DIR *dir); The explain_readdir function is used to obtain an explanation of an error returned by the readdir(2) system call. The least the message will contain is the value of strerror(errno), but usually it will do much better, and indicate the underlying cause in more detail. The errno global variable will be used to obtain the error value to be decoded. This function is intended to be used in a fashion similar to the following example: errno = 0; struct dirent *dep = readdir(dir); if (!dep && errno != 0) { fprintf(stderr, "%s ", explain_readdir(dir)); exit(EXIT_FAILURE); } dir The original dir, exactly as passed to the readdir(2) system call. Returns: The message explaining the error. This message buffer is shared by all libexplain functions which do not supply a buffer in their argument list. This will be overwritten by the next call to any libexplain function which shares this buffer, including other threads. Note: This function is not thread safe, because it shares a return buffer across all threads, and many other functions in this library. explain_errno_readdir const char *explain_errno_readdir(int errnum, DIR *dir); The explain_errno_readdir function is used to obtain an explanation of an error returned by the readdir(2) system call. The least the mes- sage will contain is the value of strerror(errnum), but usually it will do much better, and indicate the underlying cause in more detail. This function is intended to be used in a fashion similar to the following example: errno = 0; struct dirent *dep = readdir(dir); int err = errno; if (!dep && errno != 0) { fprintf(stderr, "%s ", explain_errno_readdir(err, dir)); exit(EXIT_FAILURE); } errnum The error value to be decoded, usually obtained from the errno global variable just before this function is called. This is neces- sary if you need to call any code between the system call to be explained and this function, because many libc functions will alter the value of errno. dir The original dir, exactly as passed to the readdir(2) system call. Returns: The message explaining the error. This message buffer is shared by all libexplain functions which do not supply a buffer in their argument list. This will be overwritten by the next call to any libexplain function which shares this buffer, including other threads. Note: This function is not thread safe, because it shares a return buffer across all threads, and many other functions in this library. explain_message_readdir void explain_message_readdir(char *message, int message_size, DIR *dir); The explain_message_readdir function may be used to obtain an explanation of an error returned by the readdir(2) system call. The least the message will contain is the value of strerror(errno), but usually it will do much better, and indicate the underlying cause in more detail. The errno global variable will be used to obtain the error value to be decoded. This function is intended to be used in a fashion similar to the following example: errno = 0; struct dirent *dep = readdir(dir); if (!dep && errno != 0) { char message[3000]; explain_message_readdir(message, sizeof(message), dir); fprintf(stderr, "%s ", message); exit(EXIT_FAILURE); } message The location in which to store the returned message. If a suitable message return buffer is supplied, this function is thread safe. message_size The size in bytes of the location in which to store the returned message. dir The original dir, exactly as passed to the readdir(2) system call. explain_message_errno_readdir void explain_message_errno_readdir(char *message, int message_size, int errnum, DIR *dir); The explain_message_errno_readdir function may be used to obtain an explanation of an error returned by the readdir(2) system call. The least the message will contain is the value of strerror(errnum), but usually it will do much better, and indicate the underlying cause in more detail. This function is intended to be used in a fashion similar to the following example: errno = 0; struct dirent *dep = readdir(dir); int err = errno; if (!dep && errno != 0) { char message[3000]; explain_message_errno_readdir(message, sizeof(message), err, dir); fprintf(stderr, "%s ", message); exit(EXIT_FAILURE); } message The location in which to store the returned message. If a suitable message return buffer is supplied, this function is thread safe. message_size The size in bytes of the location in which to store the returned message. errnum The error value to be decoded, usually obtained from the errno global variable just before this function is called. This is neces- sary if you need to call any code between the system call to be explained and this function, because many libc functions will alter the value of errno. dir The original dir, exactly as passed to the readdir(2) system call. SEE ALSO
readdir(2) read directory entry explain_readdir_or_die(3) read directory entry and report errors COPYRIGHT
libexplain version 0.52 Copyright (C) 2008 Peter Miller explain_readdir(3)
All times are GMT -4. The time now is 05:07 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy