Shell scripting

id,name,id_2, success/failure
44,RAJ, 33, SUCCESS
40,JEY, 44,FAILURE
44,RAJ, 33, FAILURE
40,JEY, 44,FAILURE
40,JEY, 44,FAILURE
44,RAJ, 33,FAILURE

THIS IS MY FILE. I WANT OUTPUT AS.

id,name,id_2,success/failure,TOTAL
44,RAJ,33,SUCCESS=1/FAILURE=2, TOTAL=3
40,JEY,44,SUCCESS=0/FAILURE=3, TOTAL=3

CAN ANYONE HELP ME WITH DIS PLEASE.THANKS

Using Scrutinizer's solution from previous post.

$ cat file
id,name,id_2, success/failure
44,RAJ, 33, SUCCESS
40,JEY, 44,FAILURE
44,RAJ, 33, FAILURE
40,JEY, 44,FAILURE
40,JEY, 44,FAILURE
44,RAJ, 33,FAILURE

$ awk -F, 'NR==1{print}
NR>1{gsub(" ","",$0);A[$1","$2","$3]; B[$4] ; C[$1","$2","$3,$4]++}END{for(i in A){p=i; for(j in B){k+=C[i,j];p=p FS j "=" C[i,j]+0;} print p ",Total=" k;k=0}}' file

id,name,id_2, success/failure
40,JEY,44,FAILURE=3,SUCCESS=0,Total=3
44,RAJ,33,FAILURE=2,SUCCESS=1,Total=3
40,jJEY,44,FAILURE,=3,Total=3
40,JEY,44,SUCCESS,=0,Total=0
44,RAJ,33,FAILURE,=2,Total=2
44,RAJ,33,SUCCESS,=1,Total=1

@PAMU....I M GETTING OUTPUT THIS WAY

---------- Post updated at 02:09 AM ---------- Previous update was at 02:05 AM ----------

sorry sorry pamu ur script is correct i only did mistak thanx alot for saving my ass :stuck_out_tongue: really appreciate your work :slight_smile:

I have modified the script to get your desired output with "/" in between.:slight_smile:

$ cat file
id,name,id_2, success/failure
44,RAJ, 33, SUCCESS
40,JEY, 44,FAILURE
44,RAJ, 33, FAILURE
40,JEY, 44,FAILURE
40,JEY, 44,FAILURE
44,RAJ, 33,FAILURE

$ awk -F, 'NR==1{print}
NR>1{gsub(" ","",$0);A[$1","$2","$3]; B[$4] ; C[$1","$2","$3,$4]++}END{
for(i in A){p=i; for(j in B){k+=C[i,j];
T=T?T "/" j "=" C[i,j]+0:j "=" C[i,j]+0;} print p","T ",Total=" k;k=0;T=""}}' file

id,name,id_2, success/failure
40,JEY,44,FAILURE=3/SUCCESS=0,Total=3
44,RAJ,33,FAILURE=2/SUCCESS=1,Total=3

yeah i used Scrutinizer's code for previous one and your in this new one once again hats off :slight_smile:

This post is nearly the same as you posted here

I guess you can modify the script there to work for you
Why starting a new thread?

And do NOT use caps look

@pamu === i m still not getting TOTAL heading
@Jotne = ya bro i wont i m new here so sorry for tht

Please show us what you have tried.

i have a newfile now
its like dis

id,name,id_2, type,success/failure,number
44,RAJ, 33, a,SUCCESS,30
40,JEY, 44,a,FAILURE,30
44,RAJ, 33, a,FAILURE,30
40,JEY, 44,a,FAILURE,30
40,JEY, 44,a,FAILURE,30
44,RAJ, 33,a,FAILURE,30

and i have lil problem now because now i hav to add two more column in output

id,name,id_2, type, success/failure,total,number,number2(total/3*3),number3(number2/number *100)

40,JEY,44,a,FAILURE=3/SUCCESS=0,Total=3,30,3,10
44,RAJ,33,a,FAILURE=2/SUCCESS=1,Total=3,30,310

Try

$ cat file
id,name,id_2, type,success/failure,number
44,RAJ, 33, a,SUCCESS,30
40,JEY, 44,a,FAILURE,30
44,RAJ, 33, a,FAILURE,30
40,JEY, 44,a,FAILURE,30
40,JEY, 44,a,FAILURE,30
44,RAJ, 33,a,FAILURE,30

$ awk -F, 'NR==1{print}
NR>1{gsub(" ","",$0);A[$1","$2","$3","$4]=$6; B[$5] ; C[$1","$2","$3","$4,$5]++}END{
for(i in A){p=i; for(j in B){k+=C[i,j];
T=T?T "/" j "=" C[i,j]+0:j "=" C[i,j]+0;};num_1=A;num_3=(k/num_1)*100
print p","T ",Total=" k,num_1,k,num_3;k=0;T=""}}' OFS="," file

id,name,id_2, type,success/failure,number
40,JEY,44,a,FAILURE=3/SUCCESS=0,Total=3,30,3,10
44,RAJ,33,a,FAILURE=2/SUCCESS=1,Total=3,30,3,10

And one important thing - don't expect script should run on any input.
As per your input we will create any script. If input changes there is no chance that script should run for other input also.

pamu

i have a file like is with a delimiter ","
id,name,type,cp_id,status,price
23,raj,normal,32,success,30
23,raj,normal,32,success,30
23,raj,normal,32,failure,30
24,jey,normal,42,failure,30
24,jey,normal,42,failure,30
24,jey,normal,42,success,30

i want my output to consist of four new columns which are (success,failure,number(total\3*3),number_2(number/price100)
like dis.
id,name,type,cp_id,success,failure,total,price,number(total\3*3),number_2(number/price
100)
23,raj,normal,32,2,1,3,30,3,30
24,jey,normal,42,1,2,3,30,3,0

anyone can show interest to solve it for me cos i m struck cos i m just able to produce till sucess,failure.