Need help for count using shell


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need help for count using shell
# 1  
Old 10-25-2015
Need help for count using shell

Input:

Code:
person1=1234
website=google.com
website=yahoo.com

person2=3453
website=google.com
website=mail.com

person3=4590
website=facebook.com

person4=4591
website=facebook.com
website=yahoo.com
website=google.com
website=twitter.com
website=example.com

Note: There is blank splace between each person ID

Output:

Code:
Two persons registered on 2 website
One Person registered on 1 website
One person registered on 5 website

Moderator's Comments:
Mod Comment We have sent you umpteenth warnings already about the use of code tags for code and data. Please have the courtesy to heed these warnings


---------- Post updated at 03:03 PM ---------- Previous update was at 02:39 PM ----------

can someone help me on this

Last edited by Scrutinizer; 10-25-2015 at 05:02 PM.. Reason: code tags again and again and again and again...
# 2  
Old 10-25-2015
Hi, try:

Code:
awk '{T[NF-1]++} END{for(i in T) printf "%s persons registered on %s websites\n",T[i],i}' RS=  file

# 3  
Old 10-25-2015
Moderator's Comments:
Mod Comment Demanding responses to your posts in less than a half hour on a Sunday (or any day) is unreasonable. The volunteers reading and responding to your posts are not being paid to act as your programming staff.

Sending personal messages asking for help on a post is not allowed by forum rules. (And refusing to accept emails in response after requesting a response by e-mail just adds insult to injury!)

Refusing to use CODE tags in your posts after receiving numerous infractions reminding you how to use CODE tags and repeatedly asking you to follow other forum rules is getting monotonous.

Please reread the forum rules you agreed to when you joined The UNIX & Linux Forums. To strengthen what Scrutinizer has already said, further infractions may lead to you being banned from this site permanently.
This User Gave Thanks to Don Cragun For This Post:
# 4  
Old 10-25-2015
Thanks Scrutinizer,

Your code is working absolutely fine and awesome.
One more thing, can you tell me how to get the list of person id's registered in each website?

I mean
Code:
i got output 50k persons registered on 1 website. How to get that website name?

---------- Post updated at 04:44 PM ---------- Previous update was at 04:43 PM ----------

Don Cragun,

Sorry for not following rules here. I will follow going forward

---------- Post updated at 05:20 PM ---------- Previous update was at 04:44 PM ----------

Quote:
Originally Posted by Scrutinizer
Hi, try:

Code:
awk '{T[NF-1]++} END{for(i in T) printf "%s persons registered on %s websites\n",T[i],i}' RS=  file

Hi Scrutinizer,

I tried above i thought its working fine but looks like its not working correctly for Total number of persons registered on Zero websites.
# 5  
Old 10-25-2015
Quote:
Originally Posted by buzzme
[...]
Code:
i got output 50k persons registered on 1 website. How to get that website name?

[...]
I tried above i thought its working fine but looks like its not working correctly for Total number of persons registered on Zero websites.
It is not reporting just the name of one website, but rather the amount of persons (as you requested) that have only one website in their record, regardless whether it is the same domain name or not.

How does the record of a person registered on "Zero websites" looks like? You did not provide any reference to it.

Last edited by Aia; 10-25-2015 at 07:25 PM..
# 6  
Old 10-25-2015
Hello Aia,

Code:
How does the record of a person registered on "Zero websites" looks like? You did not provide any reference to it.


person1=1234
website=google.com
website=yahoo.com

person2=3453
website=google.com
website=mail.com

person3=4590
website=facebook.com

person4=4591
website=facebook.com
website=yahoo.com
website=google.com
website=twitter.com
website=example.com

person5=2359


Output:

Two persons registered on 2 website
One Person registered on 1 website
One person registered on 5 website
One person registered on 0 website

# 7  
Old 10-26-2015
Works fine on linux:
Code:
awk '{T[NF-1]++} END{for(i in T) printf "%s persons registered on %s websites\n",T[i],i}' RS=  file
1 persons registered on 0 websites
1 persons registered on 1 websites
2 persons registered on 2 websites
1 persons registered on 5 websites

What OS/awk versions do you use?

---------- Post updated at 13:23 ---------- Previous update was at 13:20 ----------

For your other requirement, try
Code:
awk '{T[NF-1]++; for (i=2; i<=NF; i++) W[$i]++} END{for(i in T) printf "%s persons registered on %s websites\n",T[i],i; for (w in W) print w, W[w]}' RS=  file
1 persons registered on 0 websites
1 persons registered on 1 websites
2 persons registered on 2 websites
1 persons registered on 5 websites
website=example.com 1
website=google.com 3
website=facebook.com 2
website=mail.com 1
website=yahoo.com 2
website=twitter.com 1

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script Shell: Count The sum of numbers in a file

Hi all; Here is my file: V1.3=4 V1.4=5 V1.1=3 V1.2=6 V1.3=6 Please, can you help me to write a script shell that counts the sum of values in my file (4+5+3+6+6) ? Thank you so much for help. Kind regards. (3 Replies)
Discussion started by: chercheur111
3 Replies

2. Shell Programming and Scripting

File Count Based on FileDate using Shell Script

I have file listed in my directory in following format -rwxrwxr-x+ 1 test test 4.9M Oct 3 16:06 test20141002150108.txt -rwxrwxr-x+ 1 test test 4.9M Oct 4 16:06 test20141003150108.txt -rwxrwxr-x+ 1 test test 4.9M Oct 5 16:06 test20141005150108.txt -rwxrwxr-x+ 1 test ... (2 Replies)
Discussion started by: krish2014
2 Replies

3. Shell Programming and Scripting

How to get the file size and count of a table using shell scripting?

Hi there, im a beginner to the shell scripting.i trying to extract a table from a db(IMD) and i have to get the count of that table and size of the file. can you help me out how to write the shall scriping for the above query. (2 Replies)
Discussion started by: pawanmamidi
2 Replies

4. Shell Programming and Scripting

frequency count using shell

Hello everyone, please consider the following lines of a matrix 59 32 59 32 59 32 59 32 59 32 59 32 59 32 60 32 60 33 60 33 60 33 60 33 60 33 60 33 60 33 60 33 60 33 (7 Replies)
Discussion started by: xshang
7 Replies

5. Shell Programming and Scripting

shell to find the count fields of each line

hi, i've many unload files with delimiter '|'. I'm trying to load them to the specific tables from those unl's. The problem here is, some unl's are corrupted. To be exact, some files doesnt seem to have the exact number of fields as in the table. So im trying to identify the corrupted... (6 Replies)
Discussion started by: dvah
6 Replies

6. Shell Programming and Scripting

Hit count on a shell script

I have a unix shell script (ex.sh) written. How to find out how many users (incl. myself) have run this .sh ? I can insert code snipet at top of script if need be. - Ravi (2 Replies)
Discussion started by: ravi368
2 Replies

7. Shell Programming and Scripting

count multiple objects in shell script

Hi all: Trying to count the number of oracle instances on HPUX 11.23 - using ksh. I have multiple instances running and I would like to have a count for how many processes for each instance. Example, run the 'ps -efu oracle' command and for each instance increment a counter. So I am looking for... (4 Replies)
Discussion started by: raggmopp
4 Replies

8. Shell Programming and Scripting

shell script to get the arrival count of file

Hello All, I have come across a small problem. It would be great if any of you could help me in resolving the issue. one file named dummy.txt will be ftped to Unix machine twice daily. If i receive it second time in a day i need to do some processing with the file. How to find the... (2 Replies)
Discussion started by: RSC1985
2 Replies

9. UNIX for Dummies Questions & Answers

Perl/shell script count the lines

Hi Guys, I want to write a perl/shell script do parse the following file input file content NPA-NXX SC 2084549 45 2084552 45 2084563 2007 2084572 45 2084580 45 3278411 45 3278430 45 3278493 530 3278507 530... (3 Replies)
Discussion started by: pistachio
3 Replies

10. UNIX for Dummies Questions & Answers

select count(*) in sqlplus into variable unix shell

Need to select count(*) from table to check for zero result in unix script (2 Replies)
Discussion started by: struggle
2 Replies
Login or Register to Ask a Question