count number of entries perl program or Unix script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting count number of entries perl program or Unix script
# 1  
Old 05-05-2012
count number of entries perl program or Unix script

Hi

I have a file with number of entries

name 1 123
name 1 345
name 1 65346
name2 3243
name2 24234
name 2 234234

so on .........

how to count total number of entries for name 1 and name2...and so on Please guide.
# 2  
Old 05-05-2012
Try,

Code:
awk 'NF==2 {a[$1] += $2} NF==3 {a[$1$2] += $3} END { for (i in a) {print i "--" a[i]}}' file

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

What script would I use to count the number of a term and its opposite?

Hello All, I am looking to write a script to count the number of a term and its opposite and create a new file with said list. I can get the terms to print to the file but only one or the other and not both. I tried this: grep -wi done */all.txt | grep -wiv done */all.txt > "filename" ... (5 Replies)
Discussion started by: mcesmcsc
5 Replies

2. AIX

UNIX ksh - To print the PID number and repeat count

This question is asked in an interview today that I have to return output with each PID number and the count of each PID number logged today. Here is the script that I have written. Can you confirm if that would work or not. The interviewer didn't said if my answer is correct or not. Can someone... (5 Replies)
Discussion started by: Subodh Kumar
5 Replies

3. UNIX for Dummies Questions & Answers

UNIX - command to count number of files in subdirectories

I have a folder named test/ and under that I have multiple directories and in each of the directory I have multiple log files. I want to know how many files exists under each sub directory. test |--quanrantine |--logfile1 |--logfile2 |--spooling |--logfile1 ... (4 Replies)
Discussion started by: ravikirankethe
4 Replies

4. UNIX for Dummies Questions & Answers

Script to count number of rows

Hi, I need a solaris shell script to read multiple files and count number of unique name rows(strings) from those files. The input and output should be like this Input: file 1 abc cde abc ... (9 Replies)
Discussion started by: ssk250
9 Replies

5. Homework & Coursework Questions

Script program to count only alphabetical characters

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: Write a shell script program to count the ONLY the number of alphabetic characters stored in the shell variable... (1 Reply)
Discussion started by: kofine05
1 Replies

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

7. Shell Programming and Scripting

perl script on how to count the total number of lines of all the files under a directory

how to count the total number of lines of all the files under a directory using perl script.. I mean if I have 10 files under a directory then I want to count the total number of lines of all the 10 files contain. Please help me in writing a perl script on this. (5 Replies)
Discussion started by: adityam
5 Replies

8. UNIX for Dummies Questions & Answers

Unix command to count the number of files with specific characters in name

Hey all, I'm looking for a command that will search a directory (and all subdirectories) and give me a file count for the number of files that contain specific characters within its filename. e.g. I want to find the number of files that contain "-a.jpg" in their name. All the searching I've... (6 Replies)
Discussion started by: murphysm
6 Replies

9. Shell Programming and Scripting

Can you run a unix script from a perl program

Hi all i have a unix script reformatter.sh i have a process whereby this script reformats a file before a perl program is used to update it i am having a little problem automating the entire process . is there a way whereby i can call the unix script from the perl program ? (12 Replies)
Discussion started by: dwightja24
12 Replies

10. Shell Programming and Scripting

hw can i count the number of character in a file by perl

i want to count the number of character contained in afile using perl cript help me out (1 Reply)
Discussion started by: trupti_rinku
1 Replies
Login or Register to Ask a Question