Operating System - HP-UX
1752809 Members
6085 Online
108789 Solutions
New Discussion юеВ

Re: Reorganise a log file using script

 
SOLVED
Go to solution
Melvin Thong
Advisor

Reorganise a log file using script

Hello,

I was given a task to write a script to reorganise a record in multiple lines into a single line identified by the ID number for example '00719 00001'. The sample log are as below:

00719 00001 maxis1d2 09/04/03 15:31:41 logger wap
logger: connection to system wap failed;
cu: Connect failed: SYSTEM NOT IN Systems FILE
00599 00001 maxis1d2 09/04/03 15:31:50 executive omcrkll6
exec: cannot execute /export/home/appadmin/bos/kevdir/a.out, errno = 2
07698 00001 maxis1d2 09/04/03 07:31:54 rtfwd
rtfwd: Error opening message log file, /bos/NOC/rts/lluminet/illuminet_log, errno 2
07724 07723 maxis1d2 09/04/03 15:32:00 alarmx
alarmx: Cannot send alarm to display
alarm display = SYS_DOWN, errno = 13, alr_errno = 72

How can I write a Unix shell script to process such log? I am facing the problem because it does not consist a fix number of line for one record. It may come from 2 or 3 lines.

Attached is the log file sample. Appreciate if you could show me how to overcome this problem.

Thank you very much.


Regards,
Melvin
3 REPLIES 3
Melvin Thong
Advisor

Re: Reorganise a log file using script

The sample log file as attached.
Robin Wakefield
Honored Contributor
Solution

Re: Reorganise a log file using script

Hi Melvin,

Something like:

awk '/^[0-9]/&&NR>1{{print""}}{printf("%s",$0)}END{print""}' logfile

should do it.

rgds, Robin
Melvin Thong
Advisor

Re: Reorganise a log file using script

Yes, it works. You are superb Robin. Thanks a lot and it solves my problem.

Regards,
Melvin