Sponsored Content
Top Forums Shell Programming and Scripting Count the repetition of a Field in File Post 302344571 by Franklin52 on Monday 17th of August 2009 04:54:45 AM
Old 08-17-2009
Quote:
Originally Posted by indian.ace

Hi frank,
there is no output for this awk script, its just publishing the same optput as input except a field saparator at the end as ",". Please can you correct it.
This is what I get:

Code:
$ cat file
abc,12345
pqr,51223
mno,72121
stu,34567
aaa,12345
pqp,11224
plm,72121
zxy,88888
fgh,12345
jkl,88888
$ awk -F, 'NR==FNR{a[$2]++;next}{print $0 "," a[$2]}' file file
abc,12345,3
pqr,51223,1
mno,72121,2
stu,34567,1
aaa,12345,3
pqp,11224,1
plm,72121,2
zxy,88888,2
fgh,12345,3
jkl,88888,2

Am I missing something?
This User Gave Thanks to Franklin52 For This Post:
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Count of Field for Non-Empty

Hi Guys, I wanted to count the number of records for a particular field of a file. whose fields are separated by comma"," I fI use this command. cat "filename" cut -sd "," -f13 | wc -l This shows all the lines count including the blank values for the field number 13. I wanted to count... (2 Replies)
Discussion started by: Swapna173
2 Replies

2. Shell Programming and Scripting

Count field frequency in a '|' delimited file

I have a large file with fields delimited by '|', and I want to run some analysis on it. What I want to do is count how many times each field is populated, or list the frequency of population for each field. I am in a Sun OS environment. Thanks, - CB (3 Replies)
Discussion started by: ChicagoBlues
3 Replies

3. Shell Programming and Scripting

How to check the repetition values in a file using bourne shell

Hi all, I have a scenario, like consider a file abc.txt, inside abc.txt, the contents is value1 = aaa, value2 = bbb, value3 = ccc, value1 = ddd. In this situation i need to throw an error for the repeatation of keys like "value1" is repeating twice. how to handle this using bourne... (1 Reply)
Discussion started by: Nandagopal
1 Replies

4. Shell Programming and Scripting

Count number of occurences of a character in a field defined by the character in another field

Hello, I have a text file with n lines in the following format (9 column fields): Example: contig00012 149606 G C 49 68 60 18 c$cccccacccccccccc^c I need to count the number of lower-case and upper-case occurences in column 9, respectively, of the... (3 Replies)
Discussion started by: s052866
3 Replies

5. Shell Programming and Scripting

Read File and Display The Count of a particular field

Hi Mates, I require help in the following: I have the following file snmp.txt Wed Mar 2 16:02:39 SGT 2011 Class : mmTrapBladeS origin : 10.0.0.0 hostname : 10.0.0.2 msg : IBM Blade Alert: Calendar Index : 10.0.0.2-IBMBLADE Fri Mar 4 07:10:54 SGT 2011 Class : mmTrapBladeS... (2 Replies)
Discussion started by: dbashyam
2 Replies

6. Shell Programming and Scripting

Help with awk for selecting lines in a file avoiding repetition

Hello, I am using Awk in UBUNTU 12.04. I have a file as following with 48,432,354 lines and 4 fields. The file has this structure (There are repetitions of the first column in several lines) AB_14 S54 A G AB_14 S55 A A AB_14 S56 G G GO_15 S45 T A GO_15 S46 A A PT_16 S33 C C PT_16 ... (4 Replies)
Discussion started by: Homa
4 Replies

7. Shell Programming and Scripting

Count the field values in a file

Hi I have a file with contents like : 101,6789556897,0000795369 - seq - fmt_recs187] - avg_recs 101,4678354769,0000835783 - seq - fmt_recs98] - avg_recs 221,5679787008,0001344589 - seq - fmt_recs1283] - avg_recs I need to find the sum of the all the values (which are in bold). here... (6 Replies)
Discussion started by: rkrish
6 Replies

8. Shell Programming and Scripting

Count of unique lines in field 4

When I use the below awk to count the unique lines in $4 for the input it seems to work. The answer is 3 because $4 is only unique 3 times in all the entries. However, when I use the same on actual data I get 56,536 and I know the answer should be 56,548. My question is there a better way to... (8 Replies)
Discussion started by: cmccabe
8 Replies

9. Shell Programming and Scripting

How to count the field and add String?

Example i have 3 fields and i wanna add my input to the field after that (NF+1) SID|Fname|Lname 123123:adds:asdasdasd Result SID|Fname|Lname|Number 123123:adds:asdasdasd:123123 ---------- Post updated at 02:36 PM ---------- Previous update was at 02:23 PM ---------- Input is likes.... (3 Replies)
Discussion started by: vutung1991
3 Replies

10. UNIX for Beginners Questions & Answers

Awk: count unique elements in a field and sum their occurence across the entire file

Hi, Sure it's an easy one, but it drives me insane. input ("|" separated): 1|A,B,C,A 2|A,D,D 3|A,B,B I would like to count the occurence of each capital letters in $2 across the entire file, knowing that duplicates in each record count as 1. I am trying to get this output... (5 Replies)
Discussion started by: beca123456
5 Replies
Count(3pm)						  LogReport's Lire Documentation						Count(3pm)

NAME
Lire::Count - Lire class that implements the count operator SYNOPSIS
use Lire::Count DESCRIPTION
Class that implements the count operator. This operator counts the number of DLF records in the current group. If the fields attribute is set, the count statistics will be equals to the number of different values present in the fields specified by that attribute. Its also possible to express the count as a ratio of the total count for the group or table. METHODS
new( %params ) Creates a new Lire::Count object. In addition to the values supported by its parents, the fields and ratio attributes will be initialized to the values specified in the %params argument. fields( [$new_fields] ) Returns the fields for which we are counting the different values. This a reference to an array of DLF field names. If the $new_fields parameter is set, it will be used as the new $fields value. It must be an array reference and should only contains valid field names for the current report specification's schema. ratio([$new_ratio]) Returns how the count will be expressed. This can one of three possible values: none Default. The absolute count will be used. group The count will be expressed as a percentage of the group's count. table The count will be expressed as a percentage of the table's total count. SEE ALSO
Lire::ReportSpec(3pm), Lire::ReportOperator(3pm), Lire::Aggregator(3pm), Lire::Aggregate(3pm). AUTHOR
Francis J. Lacoste <flacoste@logreport.org> VERSION
$Id: Count.pm,v 1.16 2008/03/09 19:27:31 vanbaal Exp $ COPYRIGHT
Copyright (C) 2001, 2002 Stichting LogReport Foundation LogReport@LogReport.org This file is part of Lire. Lire is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program (see COPYING); if not, check with http://www.gnu.org/copyleft/gpl.html. Lire 2.1.1 2008-03-09 Count(3pm)
All times are GMT -4. The time now is 01:52 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy