Help needed sorting syslog columns


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Help needed sorting syslog columns
# 1  
Old 10-08-2010
Help needed sorting syslog columns

Hi all,

I need your help in sorting some columns in a syslog report.

The command is:
Code:
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 cbjsw103-0101.nls.jlrint.com %LINK-4-ERROR: FastEthernet0/1 is experiencing errors
1 cbjsw140-0601.nls.jlrint.com %LINK-4-ERROR: FastEthernet0/3 is experiencing errors
3 galsw105-b107b.nls.jlrint.com %LINK-4-ERROR: FastEthernet0/26 is experiencing errors
3 galsw105-b107b.nls.jlrint.com %LINK-4-ERROR: FastEthernet0/4 is experiencing errors
6 galsw110-b118c.nls.jlrint.com %LINK-4-ERROR: FastEthernet0/6 is experiencing errors
1 galsw114-b231b.nls.jlrint.com %LINK-4-ERROR: FastEthernet0/40 is experiencing errors
10 galsw127-b521a.nls.jlrint.com %LINK-4-ERROR: FastEthernet0/3 is experiencing errors
1 galsw148-b531d.nls.jlrint.com %LINK-4-ERROR: FastEthernet0/18 is experiencing errors
1 galsw149-b531e.nls.jlrint.com %LINK-4-ERROR: FastEthernet0/13 is experiencing errors
1 galsw153-b533a.nls.jlrint.com %LINK-4-ERROR: FastEthernet0/12 is experiencing errors
8 galsw161-b541a.nls.jlrint.com %LINK-4-ERROR: FastEthernet0/33 is experiencing errors


I would like to sort the output columns in the following descending order:
Error Type (i.e. LINK-4-ERROR)
Hostname
Count

Thanks in advance,

Wynford

Last edited by vbe; 10-08-2010 at 05:44 AM.. Reason: code tags please
# 2  
Old 10-08-2010
Hi,

It may solve your problem...

Code:
sort -n -t"/" +1 -2  <output_file> | sort -t\t +2 -3 +1 -2 -n +0 -1

Thanks
# 3  
Old 10-11-2010
Hi there,

This doesn't solve my problem, I need to be able to sort on the "Message Type", then the "Hostname" then the column.

Regards, Wynford
# 4  
Old 10-12-2010
Hi,

Try this:
Code:
sort -k3.2,3 -k2,2 -k1n,1 <file>

Regards,
# 5  
Old 10-13-2010
Hi Birei,

Thanks for your code, it works fine, except I had to insert an "r" to reverse the output, as shown below.

sort -k3.2,3 -k2,2 -k1nr,1 <file>

Thank you for your help.

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 by columns

Hi, I have a tab delimited columnar file where I want to remove lines wherever two particular columns match. so for this file, I want to toss the lines where columns 1 and 2 match: a a 1 3 a b 2 4 b b 3 5 because there are matches column 1 and 2 in lines 1 and 3, I would like a script to... (2 Replies)
Discussion started by: mikey11415
2 Replies

3. Shell Programming and Scripting

CSV Sorting on only particular columns

Hello! So ive been presented with this comma-delimited file: I need a print to look as below " lastname, phone_number, zip for every person with a last name starting with the letter H, I only with a 650-area code phone number. output should be sorted by reverse ZIP code " I only have... (5 Replies)
Discussion started by: strangemachine
5 Replies

4. UNIX for Dummies Questions & Answers

Sorting by Multiple Columns

Hi I have a text file that has four columns (Logonid,First Name,Last Name,Status) Logonid First Name Last Name Status abc2 Fred Mercury Inactive abc1 John Deacon Active abc3 Roger Taylor Active abc4 Brian ... (2 Replies)
Discussion started by: theref
2 Replies

5. UNIX for Dummies Questions & Answers

Sorting by multiple columns

I have a space delimited text file that I would like to sort by multiple columns. First I want to sort by column 1, then by column 2. Both columns are numerical. Thanks! (1 Reply)
Discussion started by: evelibertine
1 Replies

6. Shell Programming and Scripting

Sorting multiple columns

Hi, We have a requirement of need to sort a file based on fields 1,3 and 4. I tried with sort command however it is not giving expected output, can we achieve any other way? Please let me know ASAP. File a e w a a b a a a a d g a a h h c d a e a a a w Output a b a a a a a w a a d... (4 Replies)
Discussion started by: Nagapandi
4 Replies

7. UNIX for Dummies Questions & Answers

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... (2 Replies)
Discussion started by: wthomas
2 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

Vertical sorting of columns

Please help to sort columns in this file: a b d f c e 1 4 10 16 7 13 2 5 11 17 8 14 3 6 12 18 9 15 I need to sort COLUMNS (so sort command doesn't work) like this: a b c d e f 1 4 7 10 13 16 2 5 8 11 14 17 3 6 9 12 15 18 I know sed can do it but don't know how... :( (7 Replies)
Discussion started by: coppuca
7 Replies

10. UNIX for Advanced & Expert Users

sorting of varchar columns

Hi , I need to sort a file based on multiple columns All the columns are of varchar type can any one give me the command to sort for varchar columns? Thanks (3 Replies)
Discussion started by: laxmi131
3 Replies
Login or Register to Ask a Question