count horizontal data


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting count horizontal data
# 1  
Old 04-11-2011
count horizontal data

dear all.. i need help

i have data
Code:
ID,A,B,C,D,E,F,G,H              --> header
917188,4,1,2,1,4,6,3,5        --> data

i want output :
Code:
ID,OUT1,OUT2,OUT3           --> header
917188,3,3,2

where OUT1 is count of 1 and 2 from $2-$9
OUT2 is count of 3 and 4 from $2-$9
OUT3 is count of 5 and 6 from $2-$9

Really appreciate your help

thanks

Last edited by Franklin52; 04-11-2011 at 04:06 PM.. Reason: Please use code tags
# 2  
Old 04-11-2011
A bit messy, but:

Code:
awk -F, 'NR==1{print $1",OUT1,OUT2,OUT3";next}{b=substr($0,length($1)); print $1","gsub(/[12]/,"",b)","gsub(/[34]/,"",b)","gsub(/[56]/,"",b)}' file

This User Gave Thanks to kato For This Post:
# 3  
Old 04-11-2011
straightforward way:

Code:
awk -F"," 'BEGIN{print "ID,OUT1,OUT2,OUT3"} 
    NR>1{o1=0;o2=0;o3=0; 
    for(i=2;i<=NF;i++){
        o1+=($i<=2)?1:0; 
        o2+=($i==3||$i==4)?1:0;
        o3+=($i==5||$i==6)?1:0;
    }
    print $1 FS o1 FS o2 FS o3}'  yourFile

This User Gave Thanks to sk1418 For This Post:
# 4  
Old 04-12-2011
Quote:
Originally Posted by kato
A bit messy, but:

Code:
awk -F, 'NR==1{print $1",OUT1,OUT2,OUT3";next}{b=substr($0,length($1)); print $1","gsub(/[12]/,"",b)","gsub(/[34]/,"",b)","gsub(/[56]/,"",b)}' file

many thanks bro... Smilie
Quote:
Originally Posted by sk1418
straightforward way:

Code:
awk -F"," 'BEGIN{print "ID,OUT1,OUT2,OUT3"} 
    NR>1{o1=0;o2=0;o3=0; 
    for(i=2;i<=NF;i++){
        o1+=($i<=2)?1:0; 
        o2+=($i==3||$i==4)?1:0;
        o3+=($i==5||$i==6)?1:0;
    }
    print $1 FS o1 FS o2 FS o3}'  yourFile

awesome... thanks so much bro..Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to count data per 5 Minutes?

Hi All could u help me, i want to count data per minutes to be 5 minutes. sample data like below : 23:40 187 23:41 200 23:42 178 23:43 171 23:44 161 23:45 145 23:46 172 23:47 163 23:48 174 23:49 174expectation : 23.40 - 23.44 897 23.45 - 23.49 828thanks (2 Replies)
Discussion started by: fajar_3t3
2 Replies

2. Shell Programming and Scripting

awk - split data based on the count

Greetings Experts, I am generating a validation query through awk and facing an issue, which I need to overcome by splitting the data based on the pattern matching count in the value of an array. File1 -- Table11@column1@date@Table21@column1@varchar(10)@d;... (4 Replies)
Discussion started by: chill3chee
4 Replies

3. UNIX for Dummies Questions & Answers

How to count no. of received data of any one files?

Hi Guys, I have a file where is different task_id and every task id has many received data, now we have to count no. of received data for any task_id. (received means received words, i.e. count no. of received word of any task_id) Please help us Guys. (5 Replies)
Discussion started by: aaditya321
5 Replies

4. Shell Programming and Scripting

Frequency Count of chunked data

Dear all, I have an AWK script which provides frequency of words. However I am interested in getting the frequency of chunked data. This means that I have already produced valid chunks of running text, with each chunk on a line. What I need is a script to count the frequencies of each string. A... (4 Replies)
Discussion started by: gimley
4 Replies

5. Shell Programming and Scripting

Count column data in a text file

I have a text file that has the following column data: 0.007 0.005 0.004 0.007 How do i output the total sum of the data above? (6 Replies)
Discussion started by: alegnagrp
6 Replies

6. Shell Programming and Scripting

Count column data

Hi Guys, B07 U51C A1 44 B1 44 Yes B07 L64U A2 44 B1 44 Yes B07 L62U A2 44 B1 44 Yes B07 L11C A4 32 B1 44 NO B05 L12Z A1 12 B1 44 NO B01 651Z A2 44 B1 44 NO B04 A51Z A2 12 B1 44 NO L07 B08D A4 12 B1 44 NO B07 RU8D A4 44 B1 44 Yes B07 L58D A4 15 B1 44 No B07 LA8D A4 44 B1 44 Yes B07... (6 Replies)
Discussion started by: asavaliya
6 Replies

7. Shell Programming and Scripting

Getting Data Count by Removing Duplicates

Hi Experts, I have many CSV data files in the below format (Example) :- Doc Number,Line Number,Condition Number 111,10,ABC 111,10,PQR 111,10,XYZ 222,20,DEF 222,20,EFG 222,20,HIJ 333,30,CCC 333,30,TCP Now, for the above data i want to get the row count based on the Doc Number & Line... (9 Replies)
Discussion started by: naikamit
9 Replies

8. Shell Programming and Scripting

Help with checking reference data frequency count

reference data GHTAS QER CC N input data NNWQERPROEGHTASTTTGHTASNCC Desired output GHTAS 2 QER 1 CC 1 N 3 (2 Replies)
Discussion started by: perl_beginner
2 Replies

9. Shell Programming and Scripting

How to extract specific data and count number containing sets from a file?

Hello everybody! I am quit new here and hope you can help me. Using an awk script I am trying to extract data from several files. The structure of the input files is as follows: TimeStep parameter1 parameter2 parameter3 parameter4 e.g. 1 X Y Z L 1 D H Z I 1 H Y E W 2 D H G F 2 R... (2 Replies)
Discussion started by: Daniel8472
2 Replies

10. Shell Programming and Scripting

count data separate by comma

hi experts, i have some problem with count data which separate by comma, below sample data : 01,011222823b6d,011222823f29,0028a5,002993,6212345678, 659111111111,6598204507,6281105008,6596197849,_,525016160836958,_, ffffffff,000000000000000000000000,_,_,_,fd,fd,ff,00,1,0028a5-002993,_,... (10 Replies)
Discussion started by: bucci
10 Replies
Login or Register to Ask a Question