Sponsored Content
Top Forums Shell Programming and Scripting Emulate group-by in shell script Post 302994408 by Scrutinizer on Wednesday 22nd of March 2017 02:09:13 PM
Old 03-22-2017
Hi, try:
Code:
awk '
  NR==1 {
    next
  }

  !($1 in L) {
    L[$1]=$2
  }

  $2<L[$1] {
    L[$1]=$2
  } 

  $2>=H[$1] {
    H[$1]=$2
  }

  END {
    for(i in L) print i, L[i], H[i]
  }
' FS=, OFS=,  file


Last edited by Scrutinizer; 03-24-2017 at 02:14 AM.. Reason: Added header skip
This User Gave Thanks to Scrutinizer For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script to emulate ls -lh?

Does anyone have a script they would like to share that emulates "ls -lh" in ksh on Solaris 8? Yeah, I know. Real men don't need that wimpy "h." Well, I'm a wimp. ;) (0 Replies)
Discussion started by: shew01
0 Replies

2. Shell Programming and Scripting

Shell quiz: emulate an associative array

Most shells flavors do not have associative arrays a.k.a. maps. How would you emulate an associative array? I had this problem once and found a working solution, but I don't want to spoil the game hence I wont tell it. Wonder if anyone comes up with something better. (5 Replies)
Discussion started by: colemar
5 Replies

3. Shell Programming and Scripting

HELP! Group by in shell script (awk/sed?)

Hello, Could some expert soul please help me with this? I have following file format - task time abc 5 xyz 4 abc 5 xyz 3 ddd 10 ddd 2 I need to generate output as - task ... (5 Replies)
Discussion started by: sncoupons
5 Replies

4. Shell Programming and Scripting

How to emulate ^S/^Q from a script

Hi, I wrote a little menu script that searches through another script you specify and displays step-names and next to it the text of the step. The scripts are converted JCL from mainframe. It alows you to select steps you want and will then create a new script which includes only the steps you... (5 Replies)
Discussion started by: AliceD
5 Replies

5. Shell Programming and Scripting

Shell script to rename a group of files

Hello, I am having 1800 files in a directory with a specified format, like amms_850o_prod.000003uNy amms_850o_prod.000003u8x amms_850o_prod.000003taP amms_850o_prod.000003tKy amms_850o_prod.000003si4 amms_850o_prod.000003sTP amms_850o_prod.000003sBg amms_850o_prod.000003rvx... (12 Replies)
Discussion started by: atlantis
12 Replies

6. Shell Programming and Scripting

"group by" using shell script?

not sure if it's called "group by" , but what i'm going to do is like this: i have a file below: 192.168.1.10 192.168.1.10 192.168.1.10 192.168.1.11 192.168.1.15 192.168.1.15 192.168.1.20 192.168.1.22 then i hope to get the result like this: 192.168.1.10 : 3 192.168.1.11 : 1... (6 Replies)
Discussion started by: tiger2000
6 Replies

7. Shell Programming and Scripting

Shell Script to ignore # and take corresponding user and group

Hi, I have a following file: role.IMPACT_USER.user=admin role.IMPACT_USER.user=dd12345 role.IMPACT_USER.user=ss76767 #role.IMPACT_USER.user=root #role.IMPACT_USER.group=System role.IMPACT_USER.group=ImpactUser #Description: Allow users to login in to Impact, start and stop service... (5 Replies)
Discussion started by: dbashyam
5 Replies

8. Shell Programming and Scripting

Emulate fgrep -f in perl

Is there any equivalent of the below requirement in perl fgrep -f file1 file2 > file3 (2 Replies)
Discussion started by: aravindj80
2 Replies

9. Shell Programming and Scripting

Shell script - group by

Hi, I have text file as shown below. root 25 oracle 25 batch 30 griduser 32 admin 35 root 25 oracle 25 batch 30 griduser 32 oracle 25 batch 30 griduser 32 xuser 45 admin 35 I want to group by based on user name, and the output need to be as below. Not necessary the username to be... (10 Replies)
Discussion started by: baladelaware73
10 Replies

10. Shell Programming and Scripting

Shell Script to Group by Based on Multiple Fields in a file

Hi, I want to know if there is any simple approach to SUM a field based on group by of different fields for e.g. file1.txt contains below data 20160622|XXX1||50.00||50.00|MONEY|Plan1| 20160622|XXX1||100.00||100.00|MONEY|Plan1| 20160623|XXX1||25.00||25.00|MONEY|Plan1|... (3 Replies)
Discussion started by: cnu_theprince
3 Replies
Locale::Codes::LangExt(3pm)				 Perl Programmers Reference Guide			       Locale::Codes::LangExt(3pm)

NAME
Locale::Codes::LangExt - standard codes for language extension identification SYNOPSIS
use Locale::Codes::LangExt; $lext = code2langext('acm'); # $lext gets 'Mesopotamian Arabic' $code = langext2code('Mesopotamian Arabic'); # $code gets 'acm' @codes = all_langext_codes(); @names = all_langext_names(); DESCRIPTION
The "Locale::Codes::LangExt" module provides access to standard codes used for identifying language extensions, such as those as defined in the IANA language registry. Most of the routines take an optional additional argument which specifies the code set to use. If not specified, the default IANA language registry codes will be used. SUPPORTED CODE SETS
There are several different code sets you can use for identifying language extensions. A code set may be specified using either a name, or a constant that is automatically exported by this module. For example, the two are equivalent: $lext = code2langext('acm','alpha'); $lext = code2langext('acm',LOCALE_LANGEXT_ALPHA); The codesets currently supported are: alpha This is the set of three-letter (lowercase) codes from the IANA language registry, such as 'acm' for Mesopotamian Arabic. This is the default code set. ROUTINES
code2langext ( CODE [,CODESET] ) langext2code ( NAME [,CODESET] ) langext_code2code ( CODE ,CODESET ,CODESET2 ) all_langext_codes ( [CODESET] ) all_langext_names ( [CODESET] ) Locale::Codes::LangExt::rename_langext ( CODE ,NEW_NAME [,CODESET] ) Locale::Codes::LangExt::add_langext ( CODE ,NAME [,CODESET] ) Locale::Codes::LangExt::delete_langext ( CODE [,CODESET] ) Locale::Codes::LangExt::add_langext_alias ( NAME ,NEW_NAME ) Locale::Codes::LangExt::delete_langext_alias ( NAME ) Locale::Codes::LangExt::rename_langext_code ( CODE ,NEW_CODE [,CODESET] ) Locale::Codes::LangExt::add_langext_code_alias ( CODE ,NEW_CODE [,CODESET] ) Locale::Codes::LangExt::delete_langext_code_alias ( CODE [,CODESET] ) These routines are all documented in the Locale::Codes::API man page. SEE ALSO
Locale::Codes The Locale-Codes distribution. Locale::Codes::API The list of functions supported by this module. http://www.iana.org/assignments/language-subtag-registry The IANA language subtag registry. AUTHOR
See Locale::Codes for full author history. Currently maintained by Sullivan Beck (sbeck@cpan.org). COPYRIGHT
Copyright (c) 2011-2013 Sullivan Beck This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. perl v5.18.2 2013-11-04 Locale::Codes::LangExt(3pm)
All times are GMT -4. The time now is 05:45 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy