LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 11-28-2012, 01:25 AM   #1
pradeep rawat
LQ Newbie
 
Registered: Nov 2012
Posts: 11

Rep: Reputation: Disabled
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

Last edited by pradeep rawat; 11-28-2012 at 01:54 AM.
 
Old 11-28-2012, 02:32 AM   #2
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,241

Rep: Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325
What have you written so far?
 
Old 11-28-2012, 02:58 AM   #3
pradeep rawat
LQ Newbie
 
Registered: Nov 2012
Posts: 11

Original Poster
Rep: Reputation: Disabled
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=""}}'

but still the output is like
ID,NAME,ID_2,success/failure
44,RAJ,33,SUCCESS=1/FAILURE=2, TOTAL=3
40,JEY,44,SUCCESS=0/FAILURE=3, TOTAL=3
but i want output like


ID,NAME,ID_2,success,failure,total
44,RAJ,33,1,2,3
40,JEY,44,0,3,3
 
Old 11-28-2012, 04:15 AM   #4
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387
Please tell us what the output should be. From your first post:
Quote:
Originally Posted by pradeep rawat View Post
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
From your second post:
Quote:
output is like
ID,NAME,ID_2,success/failure
44,RAJ,33,SUCCESS=1/FAILURE=2, TOTAL=3
40,JEY,44,SUCCESS=0/FAILURE=3, TOTAL=3

i want output like
ID,NAME,ID_2,success,failure,total
44,RAJ,33,1,2,3
40,JEY,44,0,3,3
Which one is correct?

Also: Please put your script/data inside [code] ... [/code] tags it preserves all spacing. If you don't know how: LQ - BB Code List.
 
Old 11-28-2012, 04:59 AM   #5
pradeep rawat
LQ Newbie
 
Registered: Nov 2012
Posts: 11

Original Poster
Rep: Reputation: Disabled
ID,NAME,ID_2,success,failure,total
44,RAJ,33,1,2,3
40,JEY,44,0,3,3


i want my output to be this way...n sorry i m new to this site
 
Old 11-28-2012, 10:09 AM   #6
steelneck
Member
 
Registered: Nov 2005
Distribution: Slackware, Arch
Posts: 43

Rep: Reputation: 8
Code:
sed 's/\//,/;s/SUCCESS=//;s/FAILURE=//;s/TOTAL=//' infile > outfile
If you want to edit the existing file, instead of writing to another outfile, use the -i option for sed.
 
Old 11-28-2012, 11:39 PM   #7
pradeep rawat
LQ Newbie
 
Registered: Nov 2012
Posts: 11

Original Poster
Rep: Reputation: Disabled
I have a file
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 want output like this

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,30
44,RAJ,33,a,FAILURE=2/SUCCESS=1,Total=3,30,3,30
 
Old 11-29-2012, 12:11 AM   #8
pradeep rawat
LQ Newbie
 
Registered: Nov 2012
Posts: 11

Original Poster
Rep: Reputation: Disabled
thnx

Last edited by pradeep rawat; 11-29-2012 at 01:39 AM.
 
Old 11-29-2012, 01:53 AM   #9
pradeep rawat
LQ Newbie
 
Registered: Nov 2012
Posts: 11

Original Poster
Rep: Reputation: Disabled
sed -e 's/pradeep/rawat/g'
this command will replace the letter pradeep with rawat
what if i want to delet a word like FRIENDS simultaneously from the same file i m replacing pradeep. im doing this
sed -e 's/pradeep/rawat/g' && sed 's/FRIENDS//g'
but i dono why this is not happening.
 
Old 11-29-2012, 06:21 AM   #10
steelneck
Member
 
Registered: Nov 2005
Distribution: Slackware, Arch
Posts: 43

Rep: Reputation: 8
Code:
sed -e 's/pradeep/rawat/g;s/FRIENDS//g'
 
Old 11-30-2012, 10:44 AM   #11
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,823

Rep: Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957
Please use ***[code][/code]*** tags around your code and data, to preserve the original formatting and to improve readability. Do not use quote tags, bolding, colors, "start/end" lines, or other creative techniques.

If I can make a suggestion, you really should give us more information than just a before/after pair.

How exactly are we to determine what goes where? It looks like you want a count of matching lines with "SUCCESS" and "FAILURE", but you haven't explained exactly what determines a matching line. Is it all three of the first columns, or just one of them, or what?

Assuming the first case, this is what I came up with:

Code:
$ awk -F ',' 'NR==1 { next } { x=$1","$2","$3 ; at[x]++ } $4 ~ /SUCCESS/ { as[x]++ } $4 ~ /FAILURE/ { af[x]++ } END{ for (i in at){ printf "%s,SUCCESS=%s/FAILURE=%s,TOTAL=%s\n" , i , as[i]?as[i]:0 , af[i]?af[i]:0 , at[i] }}' infile.txt
40,JEY, 44,SUCCESS=0/FAILURE=3,TOTAL=3
44,RAJ, 33,SUCCESS=1/FAILURE=2,TOTAL=3
You can modify the printf statement as you wish.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Scripting help Manda Linux - Newbie 7 08-17-2011 02:48 PM
LXer: Scripting the Linux desktop, Part 2: Scripting Nautilus LXer Syndicated Linux News 0 02-17-2011 05:02 AM
Firefox Scripting Add-on (Scripting HTML / Javascript inside Firefox) linuxbeatswindows Programming 1 09-18-2009 11:09 PM
teaching shell scripting: cool scripting examples? fax8 Linux - General 1 04-20-2006 05:29 AM
on scripting gigsz Linux - Newbie 5 12-27-2005 03:24 AM


All times are GMT -5. The time now is 02:09 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration