simple awk sort problem


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting simple awk sort problem
# 1  
Old 11-29-2011
simple awk sort problem

Hello folks

I have the following output

Code:
UNIX95=1 ps -ef -o pcpu,user,pid,args |more
 %CPU USER       PID COMMAND
 0.03 root         0 swapper
 0.08 root         1 init
 0.00 root        13 net_str_cached
 0.00 root        12 usbhubd
 0.00 root        11 escsid
 0.00 root        10 ttisr
 0.02 root         9 ksyncer_daemon
 0.00 root         8 ioconfigd
 0.00 root         7 kai_daemon
 0.04 root         6 kmemdaemon
 0.00 root         5 signald
 0.00 root        14 net_str_cached

I would like to keep the first line (NR==1) and the sort on the cpu (first)field
Would this be possible with awk ??

TIA

Last edited by Scott; 11-29-2011 at 02:32 PM.. Reason: Please use CODE tags for code
# 2  
Old 11-29-2011
Don't think awk is really applicable here.

Code:
UNIX95=1 ps -ef -o pcpu,user,pid,args |
        (       head -n 1
                sort -n )

# 3  
Old 11-29-2011
Quote:
Originally Posted by delphys
Hello folks

I have the following output

Code:
UNIX95=1 ps -ef -o pcpu,user,pid,args |more
 %CPU USER       PID COMMAND
 0.03 root         0 swapper
 0.08 root         1 init
 0.00 root        13 net_str_cached
 0.00 root        12 usbhubd
 0.00 root        11 escsid
 0.00 root        10 ttisr
 0.02 root         9 ksyncer_daemon
 0.00 root         8 ioconfigd
 0.00 root         7 kai_daemon
 0.04 root         6 kmemdaemon
 0.00 root         5 signald
 0.00 root        14 net_str_cached

I would like to keep the first line (NR==1) and the sort on the cpu (first)field
Would this be possible with awk ??

TIA
try like this
Code:
UNIX95=1 ps -ef -o pcpu,user,pid,args | /bin/sort -r|sed -n '1,12p'

# 4  
Old 11-29-2011
Code:
UNIX95=1 ps -ef -o pcpu,user,pid,args | (head -n1; sort -r -k 1,1) | head -10
 %CPU USER       PID COMMAND
f /u1/rjl/db.pf -p gnpr/gnmenum -q -mmax 1024
16.66 progress 22668 /usr/dlc/bin/_progres -b -pf /u2/oms/bin/client/rjl/unixclnt.pf -p ommsgmon/msgmon.r
 3.74 progress  7776 /usr/dlc/bin/_mprosrv /u0/data/rjl/exc2sm -m1 -N TCP -Nd /dev/tcp -hs 0 -Mm 1024 -yy 1960 -cpinternal ISO8859-1 -cpstream ISO88
 3.62 progress  5009 /usr/dlc/bin/_mprosrv /u0/data/rjl/exc2 -m1 -N TCP -Nd /dev/tcp -hs 0 -Mm 1024 -yy 1960 -cpinternal ISO8859-1 -cpstream ISO8859
 3.59 progress 26837 /usr/dlc/bin/_proapsv -logginglevel 3 -logfile /u2/dba_logs/appserver/asrjl.server.log -ubpid 26097 -Ms 1 -logname asrjl -logen
 3.45 progress 12908 /usr/dlc/bin/_mprosrv /u0/data/rjl/exc2 -m1 -N TCP -Nd /dev/tcp -hs 0 -Mm 1024 -yy 1960 -cpinternal ISO8859-1 -cpstream ISO8859
 3.42 progress 26097 /opt/java/jre/bin/IA64W/java -Xverbosegc1:file=/u2/dba_logs/appserver/gc/asrjl.gc.log -Xms32m -Xmx128m -Xss512k -classpath /u0/
 3.32 progress  7746 /usr/dlc/bin/_mprosrv /u0/data/rjl/exc2 -m1 -N TCP -Nd /dev/tcp -hs 0 -Mm 1024 -yy 1960 -cpinternal ISO8859-1 -cpstream ISO8859
 3.27 progress  8741 /usr/dlc/bin/_mprosrv /u0/data/rjl/exc2 -m1 -N TCP -Nd /dev/tcp -hs 0 -Mm 1024 -yy 1960 -cpinternal ISO8859-1 -cpstream ISO8859

Thank you very much but there seems to be an undesirable output line:

Code:
f /u1/rjl/db.pf -p gnpr/gnmenum -q -mmax 1024

I think this is the very last line from the original command .. any idea as to how to suppress it ??
Thnx again !!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Simple awk search problem

Hello; we have : awk '/reg_exp/,0/ prints every line after the first occurrence of "reg_exp" But if I want to print rest of the lines AFTER the last occurrence of "reg_exp", how would I do it ?? Tried : awk ' ! (/reg_exp/,0)' But it errored... Thank you for any... (5 Replies)
Discussion started by: delphys
5 Replies

2. Shell Programming and Scripting

another simple awk problem

Hello; I need to print two previous lines after searching for a reg exp: awk '/haywood/' should produce the following =================== p9J46THe020804 89922 Tue Oct 18 21:06 MAILER-DAEMON (host map: lookup (haywood.com): deferred) ... (1 Reply)
Discussion started by: delphys
1 Replies

3. Shell Programming and Scripting

Simple awk problem II

Hello; Trying to figure out how to keep just the contents between the two search lines: awk '/regexp_1/ ,/regexp_2/' I do not want lines containing regexp_1 and regexp_2 in the output. Thank you for any ideas Video tutorial on how to use code tags in The UNIX and Linux Forums. (5 Replies)
Discussion started by: delphys
5 Replies

4. Shell Programming and Scripting

simple awk problem

Hello; I have the following log file: 10/11/11 10:42:02 LOCK Q Userid:284 Username=root UserPID:23158 Device:marlin batch 10/11/11 10:42:02 TableNr:226 TableName:iatkn RecId:116290398 Flags:X Q H 10/11/11 10:42:02 LOCK CONTENTION X 10/11/11 10:42:02 ... (3 Replies)
Discussion started by: delphys
3 Replies

5. Shell Programming and Scripting

simple awk problem

pcn linus> ntpq -p remote refid st t when poll reach delay offset disp ============================================================================== +smpnn01 ntpsrv1 2 u 829 1024 377 1.46 0.793 0.85 *smpnn02 ntpsrv1 2 u ... (2 Replies)
Discussion started by: arch12
2 Replies

6. Shell Programming and Scripting

Simple sort with header

Hi, Please help with this problem. Somehow does not work for me. test.txt CHR SNP BP A1 C_A C_U A2 CHISQ P OR 19 rs10401969 19268718 C 222 890 T 0.03462 0.8524 0.9857 1 rs10873889 ... (4 Replies)
Discussion started by: genehunter
4 Replies

7. Programming

sort problem

I am in need of some direction. First off I want to admit this is an assignment but I have hit a block. I need to sort, by the number of times a string occurs (count), and output the top 10. I have found what number gives me the top 10 so from there I need to know how to sort them. Any... (1 Reply)
Discussion started by: Cn00b
1 Replies

8. Shell Programming and Scripting

awk gsub simple problem

Hi New to shell script and awk and need assistance on this problem. I need to use a variable to substitute a string in an external file and write the changed info to another file. At first I did not know if you could use a variable as the sub value but the following showed me that I can. ... (3 Replies)
Discussion started by: hukcjv
3 Replies

9. Shell Programming and Scripting

Simple AWK script problem.

Hi all, I have set up a simple awk script to calculate the average of values that are printed out a number of times per second (the number of time the printing occurs varies). The data is of the format shown below: 1 4.43 1 3.65 1 2.45 2 7.65 2 8.23 2 5.65 3 4.65 3 6.21 .. .. 120... (4 Replies)
Discussion started by: omnomtac
4 Replies

10. Shell Programming and Scripting

how to use awk to sort this problem out

there has several numbers which are:1,2,3,45,6,7,8,9,0,10,34,34,54,122,6756,54,87,99,2,1,45; how to write a shell script orts the above numbers into descending order and puts them into and arrray and also find and prints the minimum and maximum of those numbers, and finds and prints the average... (4 Replies)
Discussion started by: sonicstage
4 Replies
Login or Register to Ask a Question