Sponsored Content
Top Forums Shell Programming and Scripting awk Group By and count string occurrences Post 302841811 by Royi on Thursday 8th of August 2013 03:45:24 AM
Old 08-08-2013
awk Group By and count string occurrences

Hi Gurus,
I'm scratching my head over and over and couldn't find the the right way to compose this AWK properly - PLEASE HELP Smilie

Input:
Code:
c,d,e,CLICK
a,b,c,CLICK
a,b,c,CONV
c,d,e,CLICK
a,b,c,CLICK
a,b,c,CLICK
a,b,c,CONV
b,c,d,CLICK
c,d,e,CLICK
c,d,e,CLICK
b,c,d,CONV
a,b,c,CLICK
b,c,d,CLICK
b,c,d,CLICK
c,d,e,CLICK

Desired Output:
Code:
a,b,c,4,2
b,c,d,3,1
c,d,e,5,0

##Explenation: the Key (group by) is fields $1+$2+$3
##The 4th column counts the occurrences of "CLICK"
##The 5th column counts the occurrences of "CONV"

Last edited by Franklin52; 08-08-2013 at 09:56 AM.. Reason: Please use Code Tags
 

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

count occurrences and substitute with counter

Hi Unix-Experts, I have a textfile with several occurrences of some string XXX. I'd like to count all the occurrences and number them in reverse order. E.g. input: XXX bla XXX foo XXX output: 3 bla 2 foo 1 I tried to achieve this with sed, but failed. Any suggestions? Thanks in... (4 Replies)
Discussion started by: ptob
4 Replies

2. Shell Programming and Scripting

Awk-Group count of field

Hi, Suppose if i am having a file with following records as given below. 5555 6756 5555 4555 4555 6767 how can i get the count of each record using AWK. Eg:5555 count should be 2 4555 count should be 2 6767 count should be 1 ... (5 Replies)
Discussion started by: tinivt
5 Replies

3. Shell Programming and Scripting

Help with Unix and Awk to count number of occurrences

Hi, I have a file (movies.sh), this file contains list of movies such as I want to redirect the movies from movies.sh to file_to_process to allow me process the file with out losing anything. I have tried Movies.sh >> file_to_process But I want to add the row number to the data... (2 Replies)
Discussion started by: INHF
2 Replies

4. Shell Programming and Scripting

Count occurrences in awk

Hello, I have an output from GDB with many entries that looks like this 0x00007ffff7dece94 39 in dl-fini.c 0x00007ffff7dece97 39 in dl-fini.c 0x00007ffff7ab356c 50 in exit.c 0x00007ffff7aed9db in _IO_cleanup () at genops.c:1022 115 in dl-fini.c 0x00007ffff7decf7b in _dl_sort_fini (l=0x0,... (6 Replies)
Discussion started by: ikke008
6 Replies

5. Shell Programming and Scripting

How to count occurrences in a specific column

Hi, I need help to count the number of occurrences in $3 of file1.txt. I only know how to count by checking one by one and the code is like this: awk '$3 ~ /aku hanya poyo/ {++c} END {print c}' FS="\t" file1.txt But this is not wise to do as i have hundreds of different occurrences in that... (10 Replies)
Discussion started by: redse171
10 Replies

6. Shell Programming and Scripting

Speed : awk command to count the occurrences of fields from one file present in the other file

Hi, file1.txt AAA BBB CCC DDD file2.txt abc|AAA|AAAabcbcs|fnwufnq bca|nwruqf|AAA|fwfwwefwef fmimwe|BBB|fnqwufw|wufbqw wcdbi|CCC|wefnwin|wfwwf DDD|wabvfav|wqef|fwbwqfwfe i need the count of rows of file1.txt present in the file2.txt required output: AAA 2 (10 Replies)
Discussion started by: mdkm
10 Replies

7. Shell Programming and Scripting

Count occurrences in first column

input amex-11 10 abc amex-11 20 bcn amed-12 1 abc I tried something like this. awk '{h++}; END { for(k in h) print k, h }' rm1 output amex-11 1 10 abc amex-11 1 20 bcn amed-12 2 1 abc Note: The second column represents the occurrences. amex-11 is first one and amed-12 is the... (5 Replies)
Discussion started by: quincyjones
5 Replies

8. Shell Programming and Scripting

Count the number of string occurrences to display 0 entries in output

Hello Friends, Can somebody assist an issue I am having? I have a separate file with a list of account ids XXX200B02Y01 XXX200B03Y01 XXX200B05Y01 XXX200B07Y01 XXX200B08Y01 I call the file, and run an egrep against a directory and logfiles AccountID=$(cat... (2 Replies)
Discussion started by: liketheshell
2 Replies

9. UNIX for Beginners Questions & Answers

awk or sed script to count number of occurrences and creating an average

Hi Friends , I am having one problem as stated file . Having an input CSV file as shown in the code U_TOP_LOGIC/U_HPB2/U_HBRIDGE2/i_core/i_paddr_reg_2_/Q,1,1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,0,0... (4 Replies)
Discussion started by: kshitij
4 Replies
SSH-CONV(1)							    Lsh Manuals 						       SSH-CONV(1)

NAME
ssh-conv - script to convert OpenSSH/SSH2 keys to lsh format SYNOPSIS
ssh-conv [OPTION...] DESCRIPTION
CAUTION! The information in this manpage may be invalid or outdated. For authorative information on lsh, please see it's Texinfo manual (see the SEE ALSO section). Converts an OpenSSH style public key to spki format used by lsh. Reads the key from stdin and outputs the converted key on stdout. Example usage: $ ssh-conv < /home/pont/.ssh/id_dsa.pub lsh-decode-key: lsh-decode-key: Reading key of type ssh-dss... {KDEwOnB1YmxpYy1rZXkoMzpkc2EoMTpwMTI5OgD1qRFBMowgnnOzjOp3HptHWf9836wy/3 F59d8DfWWehKgy8DNISgmzCnRNXReL/5PvTZwFID2KvEYfyxAYy4uTSJbtkzDfsicGWi7n YbXu2VpWHpNdhsaKrEu9iXmQb4JoN1grC0QsaCZrngACZRKEAklPH9ubwCMBK55yRP27gy koMTpxMjE6AIoOrpe064y7L2oYQqBE3sNskW19KSgxOmcxMjg6Olyu4xMIWsUBeVnbg2oU BvvbcsnHHhHyDVHmMZ1ERhDCLl6gjIsbWjBIBIXZUaFJ6AO236CfgdM5Rop5XYmcIIA9G7 QD2GWTe48MGdjFQVyr2SKoDiNFKSJXqHVYzZJeosvz6FyTDt7aGNGqcL0tG7GXl9savALt RSQRfO9JlOcpKDE6eTEyOToAwyzp6sIt6KsLhFoeM9ADA7opHq4lFT6bS8su9g3KBGqGG4 JNsEN9CI5SnLpqsfVm5SxmqPMPJvdGVOqAjjfzsv7SvfhSBUHXYeYpgci49pfc5bZCh/EY zX7bVnOVV3gQgNGeT0FN1gf9vTUMKh1VGPRfm7unXNqjBLEMYmlRwqcpKSk=} $ OPTIONS
--decode-with PROGRAM-NAME The program to use for the actual decoding. REPORTING BUGS
Report bugs to <bug-lsh@gnu.org>. COPYING
The lsh suite of programs is distributed under the GNU General Public License; see the COPYING and AUTHORS files in the source distribution for details. AUTHOR
The lsh program suite is written mainly by Niels Moller <nisse@lysator.liu.se>. This man-page was written for lsh 2.0 by Pontus Freyhult <pont_lsh@soua.net>, it is based on a template written by J.H.M. Dassen (Ray) <jdassen@wi.LeidenUniv.nl>. SEE ALSO
lsftp(1), lshg(1), lsh-authorize(1), lsh-decode-key(1), lsh-decrypt-key(1), lsh-export-key(1), lsh-keygen(1), lsh-make-seed(1), lsh- upgrade(1), lsh-upgrade-key(1), lsh-writekey(1), lshd(8) The full documentation for lsh is maintained as a Texinfo manual. If the info and lsh programs are properly installed at your site, the command info lsh should give you access to the complete manual. SSH-CONV NOVEMBER 2004 SSH-CONV(1)
All times are GMT -4. The time now is 06:32 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy