counting?


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers counting?
# 1  
Old 02-16-2012
counting?

Hi all,
I promise this is my very last dumb question.. but how to you count how many unique names you have.
My dataset is:

>Bac1
afdsgrr
>Bac4
egege
>Bac8
dgrjh
>Bac1
afdsgrr
>Bac1
afdsgrr
>Bac8
dgrjh

What i want to know is that how many unique names there is, so the output would be something like:
3

OR

>Bac1 3
>Bac4 1
>Bac8 2
# 2  
Old 02-16-2012
Not a dumb question.

Code:
awk '/^>/ { T[$1]++ } END { for(X in T) print X, T[X]; }' filename

# 3  
Old 02-16-2012
Code:
egrep -e '^>' yourfile | sort | uniq -c

# 4  
Old 02-17-2012
Thank you Smilie both are great Smilie
 
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Sequential counting

Hi have a file of the following format a1 a1 a2 a2 a4 a4 a4 a3 a3 a5 a6 a6 a6 a6 .. 100's of lines (2 Replies)
Discussion started by: Lucky Ali
2 Replies

2. Shell Programming and Scripting

counting using awk

Hi, I want to perform a task using shell script. I am new to awk programming and any help would be greatly appreciated. I have the following 3 files (for example) file1: Name count Symbol chr1_1_50 10 XXXX chr3_101_150 30 YYYY File2: Name ... (13 Replies)
Discussion started by: Diya123
13 Replies

3. Shell Programming and Scripting

Counting

Hi, The following output shows how many pmon process are started by users named : oracle or yoavb $ ps -ef |grep pmon |grep -v grep |grep -v ipmon oracle 11268 1 0 Sep 2 ? 36:00 ora_pmon_qerp oracle 17496 1 0 Oct 11 ? 8:58 ora_pmon_bcv oracle 15081 1 0 ... (5 Replies)
Discussion started by: yoavbe
5 Replies

4. Shell Programming and Scripting

Counting words

Hi Is there a way to count the no. of words in all files in directory. All are text files.I use wc -w but somehow i am not getting the rite answer. Is there an alternative. Thanks in advance (9 Replies)
Discussion started by: kinny
9 Replies

5. UNIX for Dummies Questions & Answers

counting words

if i have a long list of data, with every line beginning with an ip-address, like this: 62.165.8.187 - - "GET /bestandnaam.html HTTP/1.1" 200 5848 "http://www.domeinnaam.nl/bestandnaam.html" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)" how do i count which ip-adresses are mentioned... (3 Replies)
Discussion started by: FOBoy
3 Replies

6. Shell Programming and Scripting

Counting

Hi, I want to count how many rows are in a file for a specific column. eg. K NM K NM K NM K JK K NM K JK K NM so the file is tab-delimited. I want to count how many rows are in column 2 and how many NMs there are. I used awk awk '{OFS="\t"}; {count++} {print i,... (3 Replies)
Discussion started by: phil_heath
3 Replies

7. Shell Programming and Scripting

Counting up a variable

Hello, I am trying to write a shell script, but i encountered a problem I cant solve alone so I hope you guys can help me. The situation is: I have a script file and a config file, in my config file I set some Variables: for example: destination=(xp, xq, xt) username=testor... (3 Replies)
Discussion started by: Kenada
3 Replies

8. IP Networking

counting the packets

there are a number of clients connected to a server.... how can i count that each clients recieve ...? how do i moniter the activity of the client..? (2 Replies)
Discussion started by: damn_bkb
2 Replies

9. Shell Programming and Scripting

Help with counting files please

Hi all. If I have a unix directory with multiple files, lets say, I have some with .dat extensions, some with .txt extensions, etc etc. How in a script would I provide a count of all the different file types (so, the different extensions, I guess) in the directory?? So if I had: test.dat... (6 Replies)
Discussion started by: gerard1
6 Replies
Login or Register to Ask a Question