Counting lines for each application


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Counting lines for each application
# 8  
Old 09-07-2010
Given what it has been said already:

Code:
ps -ef | awk '{ token[substr($9,length($9)-2,3)]++} END{for (i in token) print i " : " token[i] | "sort -k3nr" }' | grep -E '[A-Z]{3}'

or
Code:
ps -ef | awk --re-interval '$9 ~ /[A-Z]{3}/ { token[substr($9,length($9)-2,3)]++} END {for (i in token) print i " : " token[i] | "sort -k3n" }'

Both lines will discard any other process that it doesn't have a pattern of: AAA, BBB, CCC, ... in the last 3 characters of the 9th field

Last edited by Aia; 09-07-2010 at 01:52 AM.. Reason: Explaining
# 9  
Old 09-07-2010
Code:
for osid in AAA BBB
do
   echo "$osid: $(ps -u oracle -f|grep -c $osid)"
done


Last edited by frank_rizzo; 09-07-2010 at 12:31 AM.. Reason: fixed logic
This User Gave Thanks to frank_rizzo For This Post:
# 10  
Old 09-07-2010
Looks fine.
Code:
awk 'NF>0 {a[$9]++}END{for (i in a) print i " : " a[i]|"sort -k3nr"}' infile

oracleAAA : 15
oracleBBB : 7
ora_ckpt_AAA : 1
ora_ckpt_BBB : 1
ora_mmon_AAA : 1
ora_psp0_AAA : 1
ora_psp0_BBB : 1
ora_qmnc_AAA : 1
ora_qmnc_BBB : 1

or do you mean you need count ora_psp0_AAA, ora_ckpt_AAA , and oracleAAA as AAA?
# 11  
Old 09-07-2010
Hi Beginer0705,

If the output you have specified is content of the file called log2 then

$ cat log2 | grep -c AAA
19
$ cat log2 | grep -c BBB
10
# 12  
Old 09-07-2010
I need to count ora_psp0_AAA, ora_ckpt_AAA , and oracleAAA as AAA.

---------- Post updated at 12:57 PM ---------- Previous update was at 12:45 PM ----------

This code works for me. Thanks everyone for your help.



for osid in AAA BBB
do
echo "$osid: $(ps -u oracle -f|grep -c $osid)"
done
# 13  
Old 09-07-2010
Quote:
Originally Posted by Beginer0705
I need to count ora_psp0_AAA, ora_ckpt_AAA , and oracleAAA as AAA.
Code:
ps -u oracle -f| awk '/AAA/ {AAA++} /BBB/{BBB++} END {print "AAA:", AAA; print "BBB:" , BBB}'
AAA: 19
BBB: 10

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Tailing and counting lines

tail -f /var/log/syslog | egrep -c FATAL is there a way to do the above and actually have the number of lines matching the pattern increment as it is logged to the log file? for instance, when you invoke a command like the one i just posted, you'll not get the total lines unless you do... (4 Replies)
Discussion started by: SkySmart
4 Replies

2. UNIX for Dummies Questions & Answers

Counting # of lines

Counting number of lines: sp I am trying to figure out a script to count the number of text files in cywig and have it give me a number (as the answer) any help would be appreciated. I am new here, so be gentle :D (3 Replies)
Discussion started by: unicksjp
3 Replies

3. Shell Programming and Scripting

sed counting lines

Hi, I'm using the command: sed -n '$=' $1 on a sh script on AIX. This script is used to count the number of lines of files. If the file has no lines at all the command doesn't return nothing. I need the command to return 0 when the file has no lines at all. How can I achieve this? Best... (5 Replies)
Discussion started by: jppedroso
5 Replies

4. UNIX for Advanced & Expert Users

Delete # of Lines after counting

I'm trying to write a script to clean up log file automatically when it reaches 1000 lines. I can't get this to work..can some help me please :) Server: SunOS 5.8 Generic_117350-53 sun4u sparc SUNW,Netra-T12 #!/bin/ksh #file reference file=`echo "$HOME/support/moe/b.tc"` #linecount... (7 Replies)
Discussion started by: moe458
7 Replies

5. Shell Programming and Scripting

Counting similar lines

Hi, I have a little problem with counting lines. I know similar topics from this forum, but they don't resolve my problem. I have file with lines like this: 2009-05-25 16:55:32,143 some text some regular expressions ect. 2009-05-25 16:55:32,144 some text. 2009-05-28 18:15:12,148 some... (4 Replies)
Discussion started by: marcinnnn
4 Replies

6. Shell Programming and Scripting

Counting lines between two patterns

Hi Guys, I have a file as follows: wwe khfgv jfo wwe jhgfd wwe wwe hoaha hao lkahe wwe (13 Replies)
Discussion started by: npatwardhan
13 Replies

7. Shell Programming and Scripting

displaying/ counting lines

I have a file called xx with the env redirected into it 5 times: env >> xx env >> xx env >> xx env >> xx env >> xx I have to read an input file (here: xx) and look for occurrences of the current user who is executing this script. Once finding an occurrence of the username I have to take that... (2 Replies)
Discussion started by: aga
2 Replies

8. UNIX for Dummies Questions & Answers

displaying/ counting lines

I have a file called xx with the env redirected into it 5 times: env >> xx env >> xx env >> xx env >> xx env >> xx I have to read an input file (here: xx) and look for occurrences of the current user who is executing this script. Once finding an occurrence of the username I have to take that... (4 Replies)
Discussion started by: aga
4 Replies

9. Linux

counting the number of lines

Hello, I have afile which begins with a few urls on multiple lines and then there is listing of some information on separate lines. The listing begins with the word Name on a given line followed by teh actual list. I want to count the number of lines in this file after the line having... (6 Replies)
Discussion started by: nayeemmz
6 Replies

10. UNIX for Dummies Questions & Answers

Counting lines and files

Hi experts, First of all thanks for all your help. How can i count the lines within a text file and send this number to another text file? And by the way how can i count the number of files inside a tape ("/dev/rtp") that as one pattern (Ex. "/CTA/") and send this number to a text file? I... (6 Replies)
Discussion started by: jorge.ferreira
6 Replies
Login or Register to Ask a Question