Sponsored Content
Top Forums Shell Programming and Scripting Emulate group-by in shell script Post 302994500 by durden_tyler on Thursday 23rd of March 2017 02:38:24 PM
Old 03-23-2017
Code:
$
$ cat data.txt
Opeation,Time-Taken
operation1,83621
operation2,72321
operation3,13288
operation2,12312
operation1,12321
operation2,45455
operation2,42543
operation1,87934
operation4,94865
operation5,27383
operation6,322
operation6,93483
operation7,3223
$
$ cat -n group_data.sh
     1  #!/usr/bin/bash
     2  header="y"
     3  while read line
     4  do
     5      if [ ! -z "$header" ] ; then
     6          header=
     7          continue
     8      fi
     9      opr=${line%%,*}
    10      if [ -z "$prev_opr" ] ; then
    11          # set min, max if first data line
    12          min=${line##*,}
    13          max=$min
    14      elif [ "$opr" != "$prev_opr" ] ; then
    15          # if opr changes, print previous line and set min, max
    16          echo "$prev_opr,$min,$max"
    17          min=${line##*,}
    18          max=$min
    19      elif [ "${line##*,}" -gt "$min" ] ; then
    20          # if opr is same, set max if needed
    21          max=${line##*,}
    22      fi
    23      prev_opr=$opr
    24  done <<< "$(sort -t, -k1,1 -k2,2n data.txt)"
    25  echo "$prev_opr,$min,$max"
    26
$
$ ./group_data.sh
operation1,12321,87934
operation2,12312,72321
operation3,13288,13288
operation4,94865,94865
operation5,27383,27383
operation6,322,93483
operation7,3223,3223
$
$

This User Gave Thanks to durden_tyler 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
fitstopnm(1)						      General Commands Manual						      fitstopnm(1)

NAME
fitstopnm - convert a FITS file into a portable anymap SYNOPSIS
fitstopnm [-image N] [-noraw] [-scanmax] [-printmax] [-min f] [-max f] [FITSfile] DESCRIPTION
Reads a FITS file as input. Produces a portable pixmap if the FITS file consists of 3 image planes (NAXIS = 3 and NAXIS3 = 3), a portable graymap if the FITS file consists of 2 image planes (NAXIS = 2), or whenever the -image flag is specified. The results may need to be flipped top for bottom; if so, just pipe the output through pnmflip -tb. OPTIONS
The -image option is for FITS files with three axes. The assumption is that the third axis is for multiple images, and this option lets you select which one you want. Flags -min and -max can be used to override the min and max values as read from the FITS header or the image data if no DATAMIN and DATAMAX keywords are found. Flag -scanmax can be used to force the program to scan the data even when DATAMIN and DATAMAX are found in the header. If -printmax is specified, the program will just print the min and max values and quit. Flag -noraw can be used to force the program to produce an ASCII portable anymap. The program will tell what kind of anymap is writing. All flags can be abbreviated to their shortest unique prefix. REFERENCES
FITS stands for Flexible Image Transport System. A full description can be found in Astronomy & Astrophysics Supplement Series 44 (1981), page 363. SEE ALSO
pnmtofits(1), pgm(5), pnmflip(1) AUTHOR
Copyright (C) 1989 by Jef Poskanzer, with modifications by Daniel Briggs (dbriggs@nrao.edu) and Alberto Accomazzi (alberto@cfa.har- vard.edu). 20 September 89 fitstopnm(1)
All times are GMT -4. The time now is 05:42 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy