Resume and count repeated values


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Resume and count repeated values
# 1  
Old 02-12-2013
Resume and count repeated values

Gents,

Please can you help me.

Input file

Code:
1050    , 9    ,9888    
1050    ,10    ,9888    
1050    ,11    ,9888    
1050    ,13    ,9888    
1050    ,15    ,9888    
1051    , 9    ,9889    
1051    ,12    ,9889    
1051    ,15    ,9889    
1051    ,18   ,9889    
1052    , 9    ,9890    
1052    ,10    ,9890    
1052    ,11    ,9890    
1052    ,15    ,9890    
1053    , 9    ,9891    
1053    ,10    ,9891    
1053    ,14    ,9891    
1054    , 9    ,9892    
1054    ,10    ,9892    
1054    ,11    ,9892

Kindly help me to get the minimun and maximun value in column 2, for each value in column 1. Then to write in a new column 4 the total of values counted.

My desired output shoul be like this:

Code:
1050    9  15    9888   5     
1051    9  18    9889   4     
1052    9  15    9890   4     
1053    9  14    9891   4     
1054    9  11    9891   3

Thanks in advance Smilie
# 2  
Old 02-12-2013
awk -F, -f ji.awk OFS='\t' myFile
where ji.awk:
Code:
{
  if (!($1 in mi) || $2<mi[$1]) mi[$1]=$2
  if (ma[$1]<$2) ma[$1]=$2
  c[$1]++
  l[$1]=$NF
}
END {
  for (i in l)
    print i,mi[i],ma[i],l[i],c[i]
}

This User Gave Thanks to vgersh99 For This Post:
# 3  
Old 02-12-2013
try also (sorted output):
Code:
awk '
{for (i=1; i<=NF; i++) $i=$i+0;
 if (!a[$1]) mx[$1]=mn[$1]=$2;
 a[$1]=$1; b[$1]=$NF; c[$1]++;
 if ($2<mn[$1]) mn[$1]=$2;
 if ($2>mx[$1]) mx[$1]=$2;
}
END {
  for (i in a) print i, mn[i], mx[i], b[i], c[i];
}
' FS="," OFS="\t" infile

This User Gave Thanks to rdrtx1 For This Post:
# 4  
Old 02-13-2013
Your help is really appreciated .. Thanks a lot

---------- Post updated at 04:05 AM ---------- Previous update was at 03:50 AM ----------

Hi rdtrx1,

How I can print other column using your script ( string value ).. I try to modify myself ,, but I got value 0,, in the colum Smilie.. I try to use printf instead of print ..but it doesn't work...

Code:
 for (i in a) print i, mn[i], mx[i], b[i], c[i];

Input file
Code:
1050    , 9    ,9888    ,N8        
1050    ,10    ,9888    ,N8        
1050    ,11    ,9888    ,N8        
1050    ,12    ,9888    ,N8        
1050    ,13    ,9888    ,N8        
1051    , 9    ,9889    ,N8        
1051    ,10    ,9889    ,N8        
1051    ,11    ,9889    ,N8        
1051    ,12    ,9889    ,N8        
1052    , 9    ,9890    ,N8        
1052    ,10    ,9890    ,N8        
1052    ,11    ,9890    ,N8        
1052    ,12    ,9890    ,N8        
1053    , 9    ,9891    ,N8        
1053    ,10    ,9891    ,N8        
1053    ,11    ,9891    ,N8        
1054    , 9    ,9892    ,N8        
1054    ,10    ,9892    ,N8        
1054    ,11    ,9892    ,N8

output file desired..

Code:
1050    9  15    9888   N8  5 
1051    9  18    9889   N8  4 
1052    9  15    9890   N8  4 
1053    9  14    9891   N8  4 
1054    9  11    9892   N8  3

Thanks for your help

---------- Post updated at 04:55 AM ---------- Previous update was at 04:05 AM ----------

I try like it... but it doesn't work Smilie

Code:
awk '                                                                                     
{for (i=1; i<=NF; i++) $i=$i+0;                                                           
 if (!a[$1]) mx[$1]=mn[$1]=$2;                                                            
 a[$1]=$1; b[$1]=$3; d[$1]=$4; c[$1]++;                                                   
 if ($2<mn[$1]) mn[$1]=$2;                                                                
 if ($2>mx[$1]) mx[$1]=$2;                                                                
}                                                                                         
END {                                                                                     
  for (i in a) print i, mn[i], mx[i], b[i], d[i], c[i];                                   
# for (i in a) printf i ("%10d,%10d,%10d,%10d,%10s\n", mn[i], mx[i], b[i], d[i], c[i];    
}                                                                                         
' FS="," OFS="\t" tmp10

# 5  
Old 02-13-2013
Try

Code:
$ sed 's/,//g' file | awk '{A[$1]++;B[$1]=$3;
less[$1]=$2<less[$1]||less[$1]?less[$1]:$2;
more[$1]=more[$1]>$2?more[$1]:$2;}
END{for(i in A)
{print i,less[i],more[i],B[i],A[i]}}'

1050 9 15 9888 5
1051 9 18 9889 4
1052 9 15 9890 4
1053 9 14 9891 3
1054 9 11 9892 3

This User Gave Thanks to pamu For This Post:
# 6  
Old 02-13-2013
Dear Pamu,

How I can get the column with N8 value as follwing:
Code:
1050    9  15    9888   N8  5

Thanks
# 7  
Old 02-13-2013
Code:
$ awk '{gsub(",","");A[$1]++;B[$1]=$3;C[$1]=$4;
less[$1]=$2<less[$1]||less[$1]?less[$1]:$2;
more[$1]=more[$1]>$2?more[$1]:$2;}
END{for(i in A)
{print i,less[i],more[i],B[i],C[i],A[i]}}' file

1050 9 13 9888 N8 5
1051 9 12 9889 N8 4
1052 9 12 9890 N8 4
1053 9 11 9891 N8 3
1054 9 11 9892 N8 3


Last edited by pamu; 02-13-2013 at 09:51 AM.. Reason: corrected
This User Gave Thanks to pamu For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Adding the values of repeated ids

File1 consist two columns, first some weired ids and second the numbers t|v203.1@t|k88711.1 0.1 t|v190.1@t|k90369.1 0.01 t|v203.1@t|k88711.1 0.5 t|v322.1@t|k88711.1 0.2 t|v207.1@t|k90369.1 0.11 t|v326.1@t|k85939.1 0.5 t|v207.1@t|k90369.1 0.7 t|v207.1@t|k90369.1 0.3 t|v326.1@t|k89421.1 0.33... (3 Replies)
Discussion started by: ashmit99
3 Replies

2. Shell Programming and Scripting

Put repeated values into a table

Hi all, I have blocks of records like the following, each block ends in = in a new line, I want tabularize the entire output. The pattern is the same in every block although not all types are there in every block. For example gine3 is absent in the second block but present first and third. ... (7 Replies)
Discussion started by: ritakadm
7 Replies

3. Shell Programming and Scripting

Finding most repeated entry in a column and giving the count

Please can you help in providing the most repeated entry in the 2nd column and give its count Here is an input file 1, This , is a forum 2, This , is a forum 1, There , is a forum 2, This , is not right Here the most repeated entry is "This" and count is 3 So output... (4 Replies)
Discussion started by: necro98
4 Replies

4. UNIX for Dummies Questions & Answers

Extracting column if above certain values and repeated over a number of times continuously

Hi I am new to the forum and would like to ask: i have a file in form with thousands of column id.1 A01 A01 A68 A68 id.2 A5 A5 A3 A3 1001 0 0 0.136 0.136 1002 0 0 0.262 0.183 1003 0 0 0.662 0.662 1004 0 0 ... (9 Replies)
Discussion started by: newbeeuk
9 Replies

5. Shell Programming and Scripting

Help in counting the no of repeated words with count in a file

Hi Pls help in solving my doubt.Iam having file like below file1.txt priya jenny jenny priya raj radhika priya bharti bharti Output required: I need a output like count of repeated words with name for ex: priya 3 jenny 2 (4 Replies)
Discussion started by: bha148
4 Replies

6. Hardware

Cannot resume from suspend with new motherboardktop, does not resume properly

I would like to get pm-suspend (or any other suspend method) working for a small new desktop computer. It is based on a Zotac GF-8200 ITX motherboard and an AMD Athlon II X@ 240 CPU using ArchLinux x86_64. The pm-suspend script works, apparently putting the machine into suspend correctly... (0 Replies)
Discussion started by: lagagnon
0 Replies

7. Shell Programming and Scripting

comparing the values of repeated keys in multiple columns

Hi Guyz The 1st column of the input file has repeated keys like x,y and z. The ist task is if the 1st column has unique key (say x) and then need to consider 4th column, if it is + symbol then subtract 2nd column value with 3rd column value (we will get 2(10-8)) or if it is - symbol subtract 3rd... (3 Replies)
Discussion started by: repinementer
3 Replies

8. Shell Programming and Scripting

To Delete the repeated occurances and print in same line by appending values

Hi All, I am trying to work on below text a b c 1 a b c 2 a b c 3 x y z 6 x y z 44 a b c 89 Need to delete the occurances and get in single line like below: a b c 1 2 3 89 x y z 6 44 89 Please help me i am new into unix scripting ..... ---------- Post updated at 03:00... (8 Replies)
Discussion started by: shaliniyadav
8 Replies

9. Programming

Count the number of repeated characters in a given string

i have a string "dfasdfasdfadf" i want to count the number of times each character is repeated.. For instance, d is repeated 4 times, f is repeated 4 times.. can u give a program in c (1 Reply)
Discussion started by: pgmfourms
1 Replies

10. What is on Your Mind?

Are companies viewing my resume? How do I track my resume visits?

Hi everybody, I am wondering if there is any tool or website out there which can track who is viewing my resume. It is very frustrating when you send your CV or Cover Letter and you receive no feedback from the company, you don't even know if they have checked it out. Thanks for your help (1 Reply)
Discussion started by: gearyipswich
1 Replies
Login or Register to Ask a Question