Help needed with adding column headings in syslog report


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Help needed with adding column headings in syslog report
# 1  
Old 10-06-2010
Help needed with adding column headings in syslog report

Hi all,
I need your help in adding column headings in the below report.
The headings I want are:
Code:
Count - Host - Message Type

The command used to create the report is as follows:
Code:
for messages in `cat syslog_message_list.txt`
do 
grep $messages syslog.`date +%d%m%y`.log | awk '{print $4 " " " " $9}' | sort | uniq -c |sort +2|sort -rk3 >> syslog.`date +%d%m%y`.report
done

Sample output:
Code:
596 cbfrt01.nls.jlrint.com %DUAL-5-NBRCHANGE:
139 cbfrt02.nls.jlrint.com %DUAL-5-NBRCHANGE:
27 cbsrt36e0-0.castlebrom.jlrint.com %DUAL-5-NBRCHANGE:
2 [192.168.23.102.199.221] %DUAL-5-NBRCHANGE:
1 cbsrt34e0-0.castlebrom.jlrint.com %DUAL-5-NBRCHANGE:
1 cbsrt33e0-0.castlebrom.jlrint.com %DUAL-5-NBRCHANGE:
1472 [19.189.126.81.193.114] %ENVMON-3-FAN_FAILED:
126 whjsw101-0102.nls.jlrint.com %LINK-4-ERROR:
73 solsw183-b38a.nls.jlrint.com %LINK-4-ERROR:
19 solsw362-nw24.nls.jlrint.com %LINK-4-ERROR:

Regards, Wynford

Last edited by Scott; 10-06-2010 at 10:31 AM.. Reason: Code tags, please...
# 2  
Old 10-06-2010
Code:
for messages in `cat syslog_message_list.txt`
do 
grep $messages syslog.`date +%d%m%y`.log | awk '{print $4 " " " " $9}' | sort | uniq -c |sort +2|sort -rk3 >> syslog.`date +%d%m%y`.report
perl -i -0pe 's/^/Count - Host - Message Type/' syslog.`date +%d%m%y`.report
done

# 3  
Old 10-06-2010
Hi Bartus11,
The column headings didn't come out right, see output below:
Code:
Count - Host - Message TypeCount - Host - Message TypeCount - Host - Message TypeCount - Host - Message TypeCoun
t - Host - Message TypeCount - Host - Message TypeCount - Host - Message TypeCount - Host - Message TypeCount -
Host - Message TypeCount - Host - Message TypeCount - Host - Message TypeCount - Host - Message TypeCount - Host
- Message TypeCount - Host - Message TypeCount - Host - Message TypeCount - Host - Message TypeCount - Host - M
essage TypeCount - Host - Message TypeCount - Host - Message TypeCount - Host - Message TypeCount - Host - Messa
ge TypeCount - Host - Message TypeCount - Host - Message TypeCount - Host - Message TypeCount - Host - Message T
ypeCount - Host - Message TypeCount - Host - Message TypeCount - Host - Message TypeCount - Host - Message TypeC
ount - Host - Message TypeCount - Host - Message TypeCount - Host - Message TypeCount - Host - Message TypeCount
- Host - Message TypeCount - Host - Message TypeCount - Host - Message TypeCount - Host - Message Type 596 cbfr
t01.nls.jlrint.com %DUAL-5-NBRCHANGE:
139 cbfrt02.nls.jlrint.com %DUAL-5-NBRCHANGE:
27 cbsrt36e0-0.castlebrom.jlrint.com %DUAL-5-NBRCHANGE:
2 [192.168.23.102.199.221] %DUAL-5-NBRCHANGE:
1 cbsrt34e0-0.castlebrom.jlrint.com %DUAL-5-NBRCHANGE:
1 cbsrt33e0-0.castlebrom.jlrint.com %DUAL-5-NBRCHANGE:
1472 [19.189.126.81.193.114] %ENVMON-3-FAN_FAILED:

Wynford

Moderator's Comments:
Mod Comment Use code tags, please.

Last edited by Scott; 10-06-2010 at 10:32 AM..
# 4  
Old 10-06-2010
Right. I've put Perl line in wrong place. This should work (also notice the added "\n"):
Code:
for messages in `cat syslog_message_list.txt`
do 
grep $messages syslog.`date +%d%m%y`.log | awk '{print $4 " " " " $9}' | sort | uniq -c |sort +2|sort -rk3 >> syslog.`date +%d%m%y`.report
done
perl -i -0pe 's/^/Count - Host - Message Type\n/' syslog.`date +%d%m%y`.report

This User Gave Thanks to bartus11 For This Post:
# 5  
Old 10-06-2010
Thanks bartus11,

That worked a treat Smilie

Regards, Wynford

---------- Post updated at 02:59 PM ---------- Previous update was at 02:51 PM ----------

Hi bartus11,

Just one more thing, how do I get perl to add a new line to seperate the column heading with an empty line from the first syslog message?
Sorry, but I don't know anything about perl.

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 with awk command on report with headings

Hi all, I have a report that looks like this: ------------------------------------------------- -- AOC - XXXXXXX -- ------------------------------------------------- Thread Last Sequence Received Last Sequence Applied Difference ----------... (12 Replies)
Discussion started by: cougartrace
12 Replies

2. Shell Programming and Scripting

Adding a column

Hello , My requirement is to add additional column sequentially to a text file based on the column value - i/p file id1|varchar id2|varchar id3|number id4|number id5|date id6|date --------------------------------------- o/p file colv1|id1 (if second column value is varchar then... (3 Replies)
Discussion started by: Pratik4891
3 Replies

3. Shell Programming and Scripting

Adding column

I have input CSV files as TS DS_WKLDNM InterfaceSpeed 29/07/2014 20:00:00 xxx112/1/18 10000000000 29/07/2014 09:00:00 xxx112/1/19 10000000000 29/07/2014 21:00:00 xxx112/1/2 10000000000 29/07/2014 20:00:00 xxx112/1/20 10000000000 29/07/2014... (10 Replies)
Discussion started by: Moon1234
10 Replies

4. Shell Programming and Scripting

Adding values of a column based on another column

Hello, I have a data such as this: ENSGALG00000000189 329 G A 4 2 0 ENSGALG00000000189 518 T C 5 1 0 ENSGALG00000000189 1104 G A 5 1 0 ENSGALG00000000187 3687 G T 5 1 0 ENSGALG00000000187 4533 A T 4 2 0 ENSGALG00000000233 5811 T C 4 2 0 ENSGALG00000000233 5998 C A 5 1 0 I want to... (3 Replies)
Discussion started by: Homa
3 Replies

5. UNIX for Dummies Questions & Answers

Rename a header column by adding another column entry to the header column name

Hi All, I have a file example.csv which looks like this GrpID,TargetID,Signal,Avg_Num CSCH74_1_1,2007,61,256 CSCH74_1_1,212007,647,679 CSCH74_1_1,12007,3,32 CSCH74_1_1,207,299,777 I want the output as GrpID,TragetID,Signal-CSCH74_1_1,Avg_Num CSCH74_1_1,2007,61,256... (1 Reply)
Discussion started by: Vavad
1 Replies

6. Shell Programming and Scripting

Rename a header column by adding another column entry to the header column name URGENT!!

Hi All, I have a file example.csv which looks like this GrpID,TargetID,Signal,Avg_Num CSCH74_1_1,2007,61,256 CSCH74_1_1,212007,647,679 CSCH74_1_1,12007,3,32 CSCH74_1_1,207,299,777 I want the output as GrpID,TragetID,Signal-CSCH74_1_1,Avg_Num CSCH74_1_1,2007,61,256... (4 Replies)
Discussion started by: Vavad
4 Replies

7. Shell Programming and Scripting

Help needed: Adding columns in csv file in loop

Hi Everyone: My shell script creates multiple csv files (~30) in for loop. I want to compile (or merge) 3rd column from each (all) of these files to another file (in loop). Please help. Thanks. (3 Replies)
Discussion started by: smap007
3 Replies

8. Shell Programming and Scripting

Adding column

Hello, I'm struggling with the following problem in sh script: Adding a column to the right-end of a file ("master-file": non-constant column number, tab and linux formatted) where the column is the 4th one of file1 (space and DOS formatted) Changing the header of column 4 of file 1 at the... (4 Replies)
Discussion started by: lco
4 Replies

9. UNIX for Dummies Questions & Answers

adding a column

Hi everybody, I've got a file with 36074 fields. I need to insert an additional new columns 2,3,4 and 5 after the first field. The columns to insert are the same for all the lines: it's "1" doe the new field 2 and "0" for the rest. I did have a look in the forum and the suggested solution I... (7 Replies)
Discussion started by: zajtat
7 Replies

10. UNIX for Dummies Questions & Answers

ls -l column headings

I'm trying to see if there's a way to see column headings when I type the ls -l command. I know what some of the fields mean for example in the following listing: total 136 drwxr-xr-x 2 root root 4096 Jun 5 15:16 bin drwxr-xr-x 3 root root 4096 Jul 9 15:25 boot drwxr-xr-x 9... (6 Replies)
Discussion started by: thoughts
6 Replies
Login or Register to Ask a Question