LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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-27-2012, 06:22 AM   #1
pradeep rawat
LQ Newbie
 
Registered: Nov 2012
Posts: 11

Rep: Reputation: Disabled
Linux script


can anyone help in this
i have a file like
2089,success
2089,failure
2087,failure
2089,success
2087,failure.
i want output like.
2089,success=2,failure=1
2087,success=1,failure=2
thanks
 
Old 11-27-2012, 06:45 AM   #2
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,800
Blog Entries: 4

Rep: Reputation: 286Reputation: 286Reputation: 286
Wierd! Do you want that when 2089 comes, 2 gets assigned to success and 1 to failure, similarly when 2087 comes, success gets 1 and failure gets 2?
Although it can be managed using a script, but specify that what's purpose of doing this.
 
Old 11-27-2012, 06:50 AM   #3
pradeep rawat
LQ Newbie
 
Registered: Nov 2012
Posts: 11

Original Poster
Rep: Reputation: Disabled
its not assigning its like script should fine unique number from table and sum the number of time success and failure are there in second column.
 
Old 11-27-2012, 07:12 AM   #4
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
An awk solution:
Code:
awk -F, '/success/{s[$1]++; a[$1]} /failure/{f[$1]++; a[$1]} END {for ( i in a ) printf "%d,success=%d,failure=%d\n", i, s[i], f[i]}' file
 
1 members found this post helpful.
  


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
How to execute a ssh script on Linux server from Windows through a bat script? wanna13e Programming 13 10-23-2009 02:41 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:56 PM.

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
Open Source Consulting | Domain Registration