Sponsored Content
Top Forums Shell Programming and Scripting Count occurrence of string in a column using awk Post 302877626 by Yoda on Monday 2nd of December 2013 03:55:36 PM
Old 12-02-2013
I noticed some inconsistencies in your required output.

If you are trying to print min and max based on column 4, then you could try:
Code:
awk '
        {
                A[$1]++
                if (!(_min[$1]))
                        _min[$1] = $4
                rmax[$1] = _max[$1] < $4 ? $0 : rmax[$1]
                rmin[$1] = _min[$1] >= $4 ? $0 : rmin[$1]
                _max[$1] = _max[$1] < $4 ? $4 : _max[$1]
                _min[$1] = _min[$1] > $4 ? $4 : _min[$1]
                next
        }
        END {
                for ( k in A )
                {
                        print A[k] OFS rmin[k]
                        if ( rmin[k] != rmax[k] )
                                print A[k] OFS rmax[k]
                }
        }
' file

Output:
Code:
4 get1 345 789 098
4 get1 600 788 451
1 fet3 789 220 278
2 get2 567 982 090
2 get2 892 321 243
2 fet4 768 222 341
2 fet4 777 610 632


Last edited by Yoda; 12-02-2013 at 05:02 PM.. Reason: removed code tags
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Count no of occurrence of the strings based on column value

Can anyone help me to count number of occurrence of the strings based on column value. Say i have 300 files with 1000 record length from which i need to count the number of occurrence string which is existing from 213 to 219. Some may be unique and some may be repeated. (8 Replies)
Discussion started by: zooby
8 Replies

2. Shell Programming and Scripting

Count number of occurrence of a string in file

if there's a file containing: money king money queen money cat money also money king all those strings are on one line in the file. how can i find out how many times "money king" shows up in the line? egrep -c "money king" wont work. (7 Replies)
Discussion started by: SkySmart
7 Replies

3. Shell Programming and Scripting

Awk: Print count for column in a file using awk

Hi, I have the following input in a file & need output as mentioned below(need counter of every occurance of field which is to be increased by 1). Input: 919143110065 919143110065 919143110052 918648846132 919143110012 918648873782 919143110152 919143110152 919143110152... (2 Replies)
Discussion started by: siramitsharma
2 Replies

4. UNIX for Dummies Questions & Answers

[Solved] Awk: count occurrence of each character for every field

Hi, let's say an input looks like: A|C|C|D A|C|I|E A|B|I|C A|T|I|B as the title of the thread explains, I am trying to get something like: 1|A=4 2|C=2|B=1|T=1 3|I=3|C=1 4|D=1|E=1|C=1|B=1 i.e. a count of every character in each field (first column of output) independently, sorted... (4 Replies)
Discussion started by: beca123456
4 Replies

5. Programming

awk to count occurrence of strings and loop for multiple columns

Hi all, If i would like to process a file input as below: col1 col2 col3 ...col100 1 A C E A ... 3 D E G A 5 T T A A 6 D C A G how can i perform a for loop to count the occurences of letters in each column? (just like uniq -c ) in every column. on top of that, i would also like... (8 Replies)
Discussion started by: iling14
8 Replies

6. UNIX for Dummies Questions & Answers

Count occurrence of string (based on type) in a column using awk

Hello, I have a table that looks like what is shown below: AA BB CC XY PQ RS AA BB CC XY RS I would like the total counts depending on the set they belong to: if search pattern is in {AA, BB, CC} --> count them as Type1 | wc -l (3 Replies)
Discussion started by: Gussifinknottle
3 Replies

7. Shell Programming and Scripting

Read first column and count lines in second column using awk

Hello all, I would like to ask your help here: I've a huge file that has 2 columns. A part of it is: sorted.txt: kss23 rml.67lkj kss23 zhh.6gf kss23 nhd.09.fdd kss23 hp.767.88.89 fl67 nmdsfs.56.df.67 fl67 kk.fgf.98.56.n fl67 bgdgdfg.hjj.879.d fl66 kl..hfh.76.ghg fl66... (5 Replies)
Discussion started by: Padavan
5 Replies

8. Shell Programming and Scripting

Count of occurrence in particular column of the file.

Hi All, let's say an input looks like: C1,C2,C3,C4,C5,C6,C7,C8,C9,C10,C11 ---------------------------------- 1|0123452|C501|Z|Z|Z|E|E|E|E|E|E|E 1|0156123|C501|X|X|X|E|E|E|E|E|E|E 1|0178903|C501|Z|Z|Z|E|E|E|E|E|E|E 1|0127896|C501|Z|Z|Z|E|E|E|E|E|E|E 1|0981678|C501|X|X|X|E|E|E|E|E|E|E ... (6 Replies)
Discussion started by: suresh_target
6 Replies

9. Shell Programming and Scripting

Column 2 string count in Column 3

My I/p is Col1|Col2|Col3 2116209997932|POSIX INC|POSIX 2116209997933|POSIX INC|POSIX 2116210089479|POSIX INC|POSIX 2116210180502|POSIX INC|POSIX 2116210512279|POSIX INC|Aero 2116210516838|POSIX INC|POSIX 2116210534342|POSIX INC|postal 2116210534345|POSIX INC|postal ... (6 Replies)
Discussion started by: nikhil jain
6 Replies

10. Shell Programming and Scripting

Count occurrence of column one unique value having unique second column value

Hello Team, I need your help on the following: My input file a.txt is as below: 3330690|373846|108471 3330690|373846|108471 0640829|459725|100001 0640829|459725|100001 3330690|373847|108471 Here row 1 and row 2 of column 1 are identical but corresponding column 2 value are... (4 Replies)
Discussion started by: angshuman
4 Replies
dlamch.f(3)							      LAPACK							       dlamch.f(3)

NAME
dlamch.f - SYNOPSIS
Functions/Subroutines DOUBLE PRECISION function dlamch (CMACH) DLAMCH DOUBLE PRECISION function dlamc3 (A, B) DLAMC3 Function/Subroutine Documentation DOUBLE PRECISION function dlamc3 (double precisionA, double precisionB) DLAMC3 Purpose: DLAMC3 is intended to force A and B to be stored prior to doing the addition of A and B , for use in situations where optimizers might hold one of these in a register. Author: LAPACK is a software package provided by Univ. of Tennessee, Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd.. Date: November 2011 Parameters: A A is a DOUBLE PRECISION B B is a DOUBLE PRECISION The values A and B. Definition at line 168 of file dlamch.f. DOUBLE PRECISION function dlamch (characterCMACH) DLAMCH Purpose: DLAMCH determines double precision machine parameters. Parameters: CMACH Specifies the value to be returned by DLAMCH: = 'E' or 'e', DLAMCH := eps = 'S' or 's , DLAMCH := sfmin = 'B' or 'b', DLAMCH := base = 'P' or 'p', DLAMCH := eps*base = 'N' or 'n', DLAMCH := t = 'R' or 'r', DLAMCH := rnd = 'M' or 'm', DLAMCH := emin = 'U' or 'u', DLAMCH := rmin = 'L' or 'l', DLAMCH := emax = 'O' or 'o', DLAMCH := rmax where eps = relative machine precision sfmin = safe minimum, such that 1/sfmin does not overflow base = base of the machine prec = eps*base t = number of (base) digits in the mantissa rnd = 1.0 when rounding occurs in addition, 0.0 otherwise emin = minimum exponent before (gradual) underflow rmin = underflow threshold - base**(emin-1) emax = largest exponent before overflow rmax = overflow threshold - (base**emax)*(1-eps) Author: Univ. of Tennessee Univ. of California Berkeley Univ. of Colorado Denver NAG Ltd. Date: November 2011 Definition at line 64 of file dlamch.f. Author Generated automatically by Doxygen for LAPACK from the source code. Version 3.4.2 Tue Sep 25 2012 dlamch.f(3)
All times are GMT -4. The time now is 02:01 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy