Sponsored Content
Top Forums Shell Programming and Scripting Count no of occurrence of the strings based on column value Post 302517137 by mirni on Tuesday 26th of April 2011 07:35:12 AM
Old 04-26-2011
It's still not very clear to me. But I'll give it a shot in the dark:
Code:
$ awk -F"-[0-9]+" '{s=gensub(/([0-9])[^0-9]*/,"\\1","g",$NF); cnt[s]++}END{for(i in cnt){print i " " cnt[i]|"sort"}}' input
A12345 7
B12345 2
C23456 2
D78636 1

THe awk command works as follows (explanation on the first line of input):
It takes the last field after dash and number(s):
Code:
IN46236 TRE 317-691-741947558020901EN1HGCM82614A0001722004HONDA ACCORD U-S- 0001-01-012011-04-112011-04-11A12345FBurd Ford, Inc.

, then it throws away everything beyond the last number
Code:
A12345FBurd Ford, Inc.

and counts the occurrences of these.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

count a occurrence

I am looking to get a output of "2 apple found" from the awk command below. black:34104 tomonorisoejima$ cat tomo apple apple black:34104 tomonorisoejima$ awk '/apple/ {count++}END{print count " apple found"}' tomo 1 apple found black:34104 tomonorisoejima$ (5 Replies)
Discussion started by: soemac
5 Replies

2. UNIX for Dummies Questions & Answers

Occurrence of two strings in a line of a file

Hi all, is there a way to find the occurrence of two strings in a line of a file? e.g. I have XXXX yyyyy zzzz 111 XXXX yyyyy zzzz 222 XXXX yyyyy zzzz 333 XXXX yyyyy zzzz 444 and want to find in one shot XXXX yyyyy zzzz 222 Thank you,... (9 Replies)
Discussion started by: f_o_555
9 Replies

3. UNIX for Dummies Questions & Answers

count number of rows based on other column values

Could anybody help with this? I have input below ..... david,39 david,39 emelie,40 clarissa,22 bob,42 bob,42 tim,32 bob,39 david,38 emelie,47 what i want to do is count how many names there are with different ages, so output would be like this .... david,2 emelie,2 clarissa,1... (3 Replies)
Discussion started by: itsme999
3 Replies

4. Shell Programming and Scripting

Count occurrence of string in a column using awk

Hi, I want to count the occurrences of strings in a column and display as in example below: Input: get1 345 789 098 get2 567 982 090 fet4 777 610 632 get1 800 544 230 get1 600 788 451 get2 892 321 243 get1 673 111 235 fet3 789 220 278 fet4 768 222 341 output: 4 get1 345 789... (7 Replies)
Discussion started by: aydj
7 Replies

5. Shell Programming and Scripting

awk to sum a column based on duplicate strings in another column and show split totals

Hi, I have a similar input format- A_1 2 B_0 4 A_1 1 B_2 5 A_4 1 and looking to print in this output format with headers. can you suggest in awk?awk because i am doing some pattern matching from parent file to print column 1 of my input using awk already.Thanks! letter number_of_letters... (5 Replies)
Discussion started by: prashob123
5 Replies

6. Shell Programming and Scripting

Insert Columns before the last Column based on the Count of Delimiters

Hi, I have a requirement where in I need to insert delimiters before the last column of the total delimiters is less than a specified number. Say if the delimiters is less than 139, I need to insert 2 columns ( with blanks) before the last field awk -F 'Ç' '{ if (NF-1 < 139)} END { "Insert 2... (5 Replies)
Discussion started by: arunkesi
5 Replies

7. 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

8. 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

9. 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

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
MB_STRRIPOS(3)								 1							    MB_STRRIPOS(3)

mb_strripos - Finds position of last occurrence of a string within another, case insensitive

SYNOPSIS
int mb_strripos (string $haystack, string $needle, [int $offset], [string $encoding = mb_internal_encoding()]) DESCRIPTION
mb_strripos(3) performs multi-byte safe strripos(3) operation based on number of characters. $needle position is counted from the beginning of $haystack. First character's position is 0. Second character position is 1. Unlike mb_strrpos(3), mb_strripos(3) is case-insensitive. PARAMETERS
o $haystack - The string from which to get the position of the last occurrence of $needle o $needle - The string to find in $haystack o $offset - The position in $haystack to start searching o $encoding - Character encoding name to use. If it is omitted, internal character encoding is used. RETURN VALUES
Return the numeric position of the last occurrence of $needle in the $haystack string, or FALSE if $needle is not found. SEE ALSO
strripos(3), strrpos(3), mb_strrpos(3). PHP Documentation Group MB_STRRIPOS(3)
All times are GMT -4. The time now is 12:04 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy