Help Needed with Sorting Output


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Help Needed with Sorting Output
# 1  
Old 10-01-2010
Help Needed with Sorting Output

Hi all,

I'm using Solaris 10, and need help in sorting the below output from the syslog file in descending rather than ascending order.
I would like both the hostname and message columns to be sorted, but right now only the message is sorted and the count column, whose order I would like reversed. I need the count column to be sorted listing the highest count at the top.

Command:
Code:
cat messages |awk '{print $4 " " " " $9}' | sort | uniq -c | sort -r|sort +2|more

Output:
Code:
   6 galsw102-b102a.nls.jlrint.com  %LINK-3-UPDOWN:
   6 whjsw213-0905.nls.jlrint.com  %LINK-3-UPDOWN:
   6 whjsw215-1001.nls.jlrint.com  %LINK-3-UPDOWN:
   7 solsw259-b71a.nls.jlrint.com  %LINK-3-UPDOWN:
   7 whjsw192-0901.nls.jlrint.com  %LINK-3-UPDOWN:
 158 solsw137-b02b.nls.jlrint.com  %LINK-3-UPDOWN:
   3 whjsw101-0102.nls.jlrint.com  %LINK-4-ERROR:
   1 cbjsw264-2004.nls.jlrint.com  %PLATFORM_ENV-1-PWR:
   1 whjsw169-0607.nls.jlrint.com  %RTD-1-ADDR_FLAP:
   2 cbjsw190-1101.nls.jlrint.com  %RTD-1-ADDR_FLAP:
   3 cbjsw198-1102.nls.jlrint.com  %RTD-1-ADDR_FLAP:
   3 cbjsw205-1103.nls.jlrint.com  %RTD-1-ADDR_FLAP:
   4 cbjsw204-1103.nls.jlrint.com  %RTD-1-ADDR_FLAP:
  42 hajsw112-0107.nls.jlrint.com  %RTD-1-LINK_FLAP:
  43 solsw137-b02b.nls.jlrint.com  %RTD-1-LINK_FLAP:

Regards, Wynford

Last edited by Scott; 10-03-2010 at 10:35 AM.. Reason: Please use code tags
# 2  
Old 10-03-2010
try changing:

Code:
cat messages |awk '{print $4 " " " " $9}' | sort | uniq -c | sort -r|sort +2|more

to

Code:
awk '{print $4 " " " " $9}' messages | sort | uniq -c | sort -k1nr,3 |more

Think that should be close to what you're after ??
# 3  
Old 10-04-2010
Hi Tytalus,

Quote:
Originally Posted by Tytalus
try changing:

Code:
cat messages |awk '{print $4 " " " " $9}' | sort | uniq -c | sort -r|sort +2|more

to

Code:
awk '{print $4 " " " " $9}' messages | sort | uniq -c | sort -k1nr,3 |more

Think that should be close to what you're after ??


---------- Post updated at 10:36 AM ---------- Previous update was at 10:27 AM ----------

Quote:
Originally Posted by Tytalus
try changing:

Code:
cat messages |awk '{print $4 " " " " $9}' | sort | uniq -c | sort -r|sort +2|more

to

Code:
awk '{print $4 " " " " $9}' messages | sort | uniq -c | sort -k1nr,3 |more

Think that should be close to what you're after ??
Hi Tytalus, et al

I actually need my output to be like the following, so that the count is in descending order listing all hosts for each message type: (I have removed the appending domain name for privacy)

118 mexsw116-mxg05s1 RTD-1-ADDR_FLAP
67 pbs051 RTD-1-ADDR_FLAP
49 mexsw107-mxc13s1 RTD-1-ADDR_FLAP
10 logmdf11se06 RTD-1-ADDR_FLAP
9 pbs041.nlse RTD-1-ADDR_FLAP
6 gnksw116-bcmso0 RTD-1-ADDR_FLAP
5 mexsw117-mxg07s1 RTD-1-ADDR_FLAP
4 mexsw122-mxl12s1 RTD-1-ADDR_FLAP
1 nyu10se01.nlse RTD-1-ADDR_FLAP
1 mexsw129-mxp19s1 RTD-1-ADDR_FLAP
1 gnksw150-br02o1 RTD-1-ADDR_FLAP
1 gnksw149-br02o0 RTD-1-ADDR_FLAP
2 fce11929 SYS-2-PS_FAIL
1 fce11926 SYS-2-PS_FAIL
1 ablsw02 SYS-2-PS_FAIL
1 ablsw01 SYS-2-PS_FAIL
1 fce11929 SYS-2-PS_INSUFFICIENT
96 wasw144a SYS-3-PORT_IN_ERRORS
4 wasw154a SYS-3-PORT_IN_ERRORS
3 wasw148a SYS-3-PORT_IN_ERRORS
2 dtsw108a SYS-3-PORT_IN_ERRORS
1 whjsw01 SYS-3-PORT_IN_ERRORS
95 wasw144a SYS-3-PORT_RUNTS
4 wasw154a SYS-3-PORT_RUNTS
2 wasw148a SYS-3-PORT_RUNTS
2 dtsw108a SYS-3-PORT_RUNTS

Regards,

Wynford

---------- Post updated at 10:59 AM ---------- Previous update was at 10:36 AM ----------

I've cracked it now, here is the command and resulting output:

cat messages |awk '{print $4 " " " " $9}' | sort | uniq -c |sort +2|sort -rk3|more

43 solsw137-b02b.nls.jlrint.com %RTD-1-LINK_FLAP:
42 hajsw112-0107.nls.jlrint.com %RTD-1-LINK_FLAP:
4 cbjsw204-1103.nls.jlrint.com %RTD-1-ADDR_FLAP:
3 cbjsw205-1103.nls.jlrint.com %RTD-1-ADDR_FLAP:
3 cbjsw198-1102.nls.jlrint.com %RTD-1-ADDR_FLAP:
2 cbjsw190-1101.nls.jlrint.com %RTD-1-ADDR_FLAP:
1 whjsw169-0607.nls.jlrint.com %RTD-1-ADDR_FLAP:
1 cbjsw264-2004.nls.jlrint.com %PLATFORM_ENV-1-PWR:
3 whjsw101-0102.nls.jlrint.com %LINK-4-ERROR:
158 solsw137-b02b.nls.jlrint.com %LINK-3-UPDOWN:
7 whjsw192-0901.nls.jlrint.com %LINK-3-UPDOWN:
7 solsw259-b71a.nls.jlrint.com %LINK-3-UPDOWN:
6 whjsw215-1001.nls.jlrint.com %LINK-3-UPDOWN:
6 whjsw213-0905.nls.jlrint.com %LINK-3-UPDOWN:

Thanks for helping.

Regards, Wynford
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help needed in sorting

I have a file which contains following lines: 0114714710147 09013 00025.00D986532147 2814714710147 09013 00045.00D985532147 Now, I need to sort the file with above bold and colured one. Means: first sorting will be done by: 147147 then by 10147 09013 after that by 986532147. The... (2 Replies)
Discussion started by: George1234
2 Replies

2. Shell Programming and Scripting

Sorting out unique values from output of for loop.

Hi , i have a belwo script which is used to get sectors per track value extarcted from Solaris machine: for DISK in /dev/dsk/c*t*d*s*; do value=`prtvtoc "$DISK" | sed -n -e '/Dimensions/,/Flags/{/Dimensions/d; /Flags/d; p; }' | sed -n -e '/sectors\/track/p'`; if ; then echo... (4 Replies)
Discussion started by: omkar.jadhav
4 Replies

3. Shell Programming and Scripting

Sorting output of AWK array

I need help to sort the output of an awk array Example datadata="1 blue 2 green 3 blue 4 yellow 5 blue 6 red 7 yellow 8 red 9 yellow 10 yellow 11 green 12 orange 13 black" My awk line to get output in one lineecho "$data" | awk ' {arr++; next} END { for (i in arr) { if(arr>1 )... (2 Replies)
Discussion started by: Jotne
2 Replies

4. Shell Programming and Scripting

sorting output of echo

can someone please tell me who to sort the numerical output of echo? UIO="8180 0 0 0 0 0 0 0 0 0 0 48240 48240 48240 48240 48240 48240 0 0 0 0 0 0 0 48300 0 0 0 48300" echo $UIO | sort -n This doesn't workk. it does not sort the numbers from smallest to highest. any ideas? (2 Replies)
Discussion started by: SkySmart
2 Replies

5. Shell Programming and Scripting

Sorting awk array output?

Hi all, I have a script which produces a nice table but I want to sort it on column 3. This is the output line in the script: # Output { FS = ":"; format = "%11s %6s %-16s\n"; prinft "\n" printf ( format, "Size","Count","Who" ) } for (i in... (21 Replies)
Discussion started by: Cowardly
21 Replies

6. HP-UX

Sorting top command output in HP_UX 11.11

Hello all, I've been woking on Solaris and Linux (Red Hat) so far but now I've inherited an HP-UX system and having minor issues with syntax...Appreciate if you could help me out here.. 1) I'm trying to sort the output of the top command in HP-UX 11.11 by pressing O (capital O) after typing... (2 Replies)
Discussion started by: luft
2 Replies

7. UNIX for Dummies Questions & Answers

Help needed sorting syslog columns

Hi all, I need your help in sorting some columns in a syslog report. The command is: for messages in `cat syslog_message_list.txt`; do grep $messages syslog.`date +%d%m%y`.log | \ tr -s " " | cut -d" " -f4,9- | sort| uniq -c >> syslog.`date +%d%m%y`.report; done The output is: 1... (4 Replies)
Discussion started by: wthomas
4 Replies

8. Shell Programming and Scripting

Help needed in sorting

Hi, Please I need urgent help in sorting below data, I had similar post but there was a kind of space in between the data but now there is no space and I have tried adjusting the old script to work but it didn't. here are the data; traceroute to 2001:1ba0:2a0:5965:0:30:24:1... (6 Replies)
Discussion started by: sam127
6 Replies

9. UNIX for Dummies Questions & Answers

sorting cksum output.

Hi guys, I have a service directory with a lot of files in. I have to cksum the whole directory and compare it to a release note document. However the problem I have is the files are listed in different lines when running cksum as they are in the release doc. Therefore cksum shows... (1 Reply)
Discussion started by: Stin
1 Replies

10. Shell Programming and Scripting

sorting output

hi, I get an output like uid=user1 gecos=user uid=user2 gecos=admin gecos=sol admin uid=user3 uid=user4 gecos=sol, admin and need it modified to: uid=user1 gecos=user (3 Replies)
Discussion started by: funksen
3 Replies
Login or Register to Ask a Question

Featured Tech Videos