The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Trouble with awk RichieFondel Shell Programming and Scripting 1 01-17-2008 07:30 AM
[question] hard exercise, help needed EnioMarques UNIX for Dummies Questions & Answers 2 09-20-2007 11:22 PM
X trouble izua UNIX for Dummies Questions & Answers 0 01-03-2007 06:19 PM
The trouble with... zazzybob What's on Your Mind? 6 01-18-2005 06:01 AM
NIS trouble farzolito UNIX for Advanced & Expert Users 10 12-10-2001 04:44 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 09-15-2007
EnioMarques EnioMarques is offline
Registered User
  
 

Join Date: Sep 2007
Location: Brazil
Posts: 8
Exclamation [question] trouble with an 'exercise'

Hello guys..
well, im kinda newbie with unix because i started to learn it like 2 weeks ago.

then i started to make some exercises, but i got stucked on this one :

Quote:
5. For each of those 3 files created on item 2:
a. Provide the TOTAL number of transactions for each sub-methods call. The sub-method call is listed in the fifth field of each line. Each field is separated by '|' (pipe) character.
b. For each sub-method call:
I. Provide the TOTAL number of SUCCESS.
II. Provide the TOTAL number of ERROR.
so, i need to know how many different 'names' has the 5th field and how many times each name appears.

i was trying with a "cut -d'|' -f5 filename | sort;" , but it only returns me all 5th field names ordered.

then i talked with few friends, they told me to use the awk command, i tried to read few manuals but i couldn't make it.

so, i would be grateful if anyone could help me with it.

thanks
and btw, sorry my bad english

Enio.


UPDATE
well, i kept trying with the awk and got the different methods name on 5th field with :

Code:
awk -F'|' '{print $5}' file1 | sort | uniq;

now i "just" need to know how many times they appear =/

Last edited by EnioMarques; 09-15-2007 at 05:23 PM..
  #2 (permalink)  
Old 09-16-2007
vgersh99's Avatar
vgersh99 vgersh99 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,131

Code:
awk -F'|' '{arr[$5]++} END {for(i in arr) printf("[%s] appeared %d times\n", i, arr[i])}' file1

  #3 (permalink)  
Old 09-16-2007
EnioMarques EnioMarques is offline
Registered User
  
 

Join Date: Sep 2007
Location: Brazil
Posts: 8
wow thanks a lot dude

but can you explain me how you did it??I wanna know how you used those indexes.

and can you give me a hand on exercise B too?? i need to know the total of ERRORS and SUCCESS.Success transactions are logged with the word INFO in the beginning of the line and and error transactions are with a ERROR instead.

i used a
Code:
grep -C INFO file1;
grep -c ERROR file1;

to know the total of errors and succes at the total,but now i need for each sub method =/


thanks in advance

Last edited by EnioMarques; 09-16-2007 at 02:59 PM..
  #4 (permalink)  
Old 09-17-2007
ajcannon ajcannon is offline
Registered User
  
 

Join Date: Aug 2007
Location: Binfield, Berkshire. UK
Posts: 91
getting totals

For any command that returns a number of lines EG 'grep INFO' you can cound the number of lines with wc -l

EG

grep INFO | wc -l

this will return the number of lines matching INFO
  #5 (permalink)  
Old 09-17-2007
EnioMarques EnioMarques is offline
Registered User
  
 

Join Date: Sep 2007
Location: Brazil
Posts: 8
ya i know, but i need to complement that A) exercise.

when i use vgersh99's code i get like :
[SubMethod1] appeared 100 times
[SubMethod3] appeared 123 times
[SubMethod2] appeared 15 times


for B) i need like..

[SubMethod1] appeared 100 times with 3 errors and 97 successful
[SubMethod2] appeared 123 times with 3 errors and 120 successful
[SubMethod3] appeared 15 times with 5 errors and 10 successful
  #6 (permalink)  
Old 09-17-2007
vgersh99's Avatar
vgersh99 vgersh99 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,131

Code:
awk -F'|' '/^INFO/{arrS[$5]++} /^ERROR/{arrE[$5]++} {arr[$5]++}END {for(i in arr) printf("[%s] appeared %d times with %d errors and %d successful\n", i, arr[i], arrE[i], arrS[i] )}' file1

Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 09:07 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0