count the number of occurance and increment


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers count the number of occurance and increment
# 1  
Old 05-17-2010
count the number of occurance and increment

Hi,

I am trying to count the number of occurance of a specific value in a column and increment the variable in the second column accordingly. I have very little information about Unix. As an example,

Code:
21 1 
32 1
32 2
45 1
56 1
56 2
56 3
73 1
82 1

Thanks,

Natasha

Moderator's Comments:
Mod Comment
Use code tags please, ty.

Last edited by zaxxon; 05-17-2010 at 05:20 AM.. Reason: code tags
# 2  
Old 05-17-2010
Try:
Code:
awk '{print $1, ++a[$1]}' file

This User Gave Thanks to Franklin52 For This Post:
# 3  
Old 05-17-2010
Thank you very much

n
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Search for a pattern in a String file and count the occurance of each pattern

I am trying to search a file for a patterns ERR- in a file and return a count for each of the error reported Input file is a free flowing file without any format example of output ERR-00001=5 .... ERR-01010=10 ..... ERR-99999=10 (4 Replies)
Discussion started by: swayam123
4 Replies

2. Shell Programming and Scripting

Need to increment number in data file

Hello, I have an Excel spreadsheet with the following data: Refntns3_1 char 30 Ref H77 nt codon 1 Reference H77 Nucleotide Codon 1 -- Codns3_1 char 30 Obs Nucleotides codon 1 Observed Nucleotides Codon 1 ... (2 Replies)
Discussion started by: deneuve01
2 Replies

3. Shell Programming and Scripting

Value Increment based on count

Hi All, I have source file x.txt 0001|0003 0031|0031 0045|0049 My desired output should be: y.txt 0001 0002 0003 0031 0045 0046 0047 (11 Replies)
Discussion started by: kmsekhar
11 Replies

4. Shell Programming and Scripting

Number of occurance with multiple conditions??

Hi, I the following sample of out put: + 6.07875 10 0 cbr 210 ------- 2 10.0 2.3 1461 19715 - 6.07875 10 0 cbr 210 ------- 2 10.0 2.3 1461 19715 + 6.07875 22 0 cbr 210 ------- 2 22.0 2.9 1301 19716 - 6.07875 22 0 cbr 210 ------- 2 22.0 2.9 1301 19716 r 6.07922 0 1 cbr 210 ------- 1 30.0... (6 Replies)
Discussion started by: ENG_MOHD
6 Replies

5. Shell Programming and Scripting

Increment a floating number in ksh

Hi ! How to increment a varibale in ksh. #!/bin/ksh set -x RELEASE_NUM=5.2.103 VAL=0.0.1 RELEASE_NUM=`echo $RELEASE_NUM + $VAL | bc` echo $RELEASE_NUM The above code is throwing this error. + RELEASE_NUM=5.2.103 (2 Replies)
Discussion started by: dashok.83
2 Replies

6. Shell Programming and Scripting

Count occurance of multiple strings using grep command

How to grep multiple string occurance in input file using single grep command? I have below input file with many IDP, RRBE messages. Out put should have count of each messages. I have used below command but it is not working grep -cH "(sent IDP Request)(Recv RRBCSM)" *.txt ... (5 Replies)
Discussion started by: sushmab82
5 Replies

7. Shell Programming and Scripting

Count the Consecutive Occurance of "X" in awk

Hi All, I have a data as follow: 0 0 0 X X 0 X X X 0 X 0 0 X 0 0 (16 Replies)
Discussion started by: nica
16 Replies

8. Shell Programming and Scripting

How to insert values in 1st occurance out of two occurance in a file

Hi I have a file which contains the following two lines which are same But I would like to insert the value=8.8.8.8 in the 1st occurance line and value=9.9.9.9 in the 2nd occurance line. <parameter name="TestIp1" value=""> <parameter name="TestIp1" value=""> Please suggest (1 Reply)
Discussion started by: madhusmita
1 Replies

9. UNIX for Dummies Questions & Answers

Count of matched pattern occurance

In a file a pattern is occured many times randomly. Even it may appear more then once in the same line too. How i can get the number of times that pattern appeared in the file? let the file name is abc.txt and the pattern is "xyz". I used the following code: grep -ic "xyz" abc.txt but it is... (3 Replies)
Discussion started by: palash2k
3 Replies

10. UNIX for Dummies Questions & Answers

count string occurance in a file hourly

Hi, I file that has all the status for one day (24hours). Now what I want to do is to count the occurence of a string in its output hourly like for example count occurance of successful or asynchronous clear destinon for every hour and redirect it to file. Please see sample file below. Please... (2 Replies)
Discussion started by: ayhanne
2 Replies
Login or Register to Ask a Question