prepare log for access


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting prepare log for access
# 1  
Old 08-11-2003
Data prepare log for access

I need help with one of my log files I got following format:
This is only a smal part of the file !

.........
--------------------------------------
2003-08-05 12:23:13.939781
logNo : 1380008
Server started - Activate; 10.48.4.51

--------------------------------------
2003-08-05 12:23:15.732659

logNo : 1380008
Server started - drives; 10.48.4.51

--------------------------------------
2003-08-05 12:23:17.845895

logNo : 1380008
Server started - oltprogramm; 10.48.4.51

--------------------------------------

.............

I need this in following format:

date;time;event
....
2003-08-05;12:23:17;Server started - oltprogramm

I search the forum for comparable threads and tried it as csh script but the csh have problems with variables biger then 1000 entries.

Is there a posibility to use perl ?
I have no experience in perl!

Thanks in advance.
joerg
# 2  
Old 08-12-2003
I'm only any good with php, but here's my two cents anyway. write a script to read the file, search (think ereg() or egrep_replace()) for \n characters, then stript them. Include a few lines to remove '-''s and entire lines containing 'logNo : '.
# 3  
Old 08-12-2003
Your requirement is a little vague. Are you showing the output for your entire sample input? If so, how do you know which entries to skip?

Perl is a fine tool for such programs, as are awk, ruby, ... But understanding your problem adequately is one key to getting a solution. (I'm prejudiced: I would never recommend a shell for a job like this.)
# 4  
Old 08-13-2003
Lightbulb

Thanx for your replay,
but now I got a solution with a lot of unix commands.
regards joerg

This is only a small part:

grep -n 'search string' losed | cut -d ':' -f1 > found
set i = 1
while 1 == 1
set aktz = `sed -n ${i}p found`
@ i++
if $aktz == '' break
@ startaktz= ( $aktz - 2 )
set str1 = `sed -n $startaktz'p' losed | cut -c1-20`
set str2 = `sed -n $aktz'p' losed`
set str = "${str1};${str2}"
echo $str >> layer
end
# 5  
Old 08-13-2003
Stuff like this reminds me why I don't use csh.Smilie Here's an awk solution. On Solaris, you have to use /usr/xpg4/bin/awk; FreeBSD 4.8 uses nawk (and perhaps awk, but on 4.8 awk is gawk, though that's changing in 5.x ...)
Code:
#!/usr/xpg4/bin/awk -f

$1 ~ /^[0-9]{4}(-[0-9]{2}){2}$/ {
        # If the first field looks like
        # a date, use it and the second field
        date = $1
        time = substr($2, 1, 8)
    }
index($0, eventname) {
        # Found the event name, so spit out the
        # name with the previously gathered date
        # and time
        split($0, a, ";")
        print date ";" time ";" a[1]
    }

Put this in a file (call it "scanlog", perhaps) and mark it executable. Then invoke it like this:
Code:
scanlog -v event=oltprogramm <losed >layer

The entire thing operates in a single pass over the file with a single process. Your solution creates 4 * n + 1 processes, where "n" is the number of events that matches your input pattern.
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How can i prepare grant staement with 2 files ?

---file1 ( tables A B C D E F ... ... Z ---file2 Joe Bob Mary Sally Fred Elmer David (1 Reply)
Discussion started by: rocking77
1 Replies

2. Shell Programming and Scripting

Prepare file run report

I have a requirement to prepare a report. We validate some incoming data fields and create validation_error reports which will contain records which do not pass validation. Once files are processed they will all be dropped under one folder. EMPLOYEE_20140915.txt... (8 Replies)
Discussion started by: member2014
8 Replies

3. Red Hat

Modprobe prepare new IP address

Hello, I m working on virtualization and saved the templates in virtual server. On creating the new Virtual machine or linux system, is there a way where during booting, it should prompt for new IP address, gateway, DNS and hostname? Or is there any configuration in linux where we can modify... (5 Replies)
Discussion started by: alnhk
5 Replies

4. UNIX for Dummies Questions & Answers

prepare a tar package

I have installed apache2 on Solaris machine with the binary. So i dont want to install the same binary across all the systems but only want to copy the lib files and the files which have been updated in this installation process. So in order to get those lib files and then prepare a tar package... (5 Replies)
Discussion started by: prash358
5 Replies

5. Shell Programming and Scripting

Prepare command before executing

Hi, Couldnt find the right string" to search for a similar question..so dont know if this has been answered yet...problem is that I want to prepare a command with the requisite parameters passed as a string before executing it...eg: the ls command .. I can pass "-l", "-t" as parameters and... (12 Replies)
Discussion started by: harman_6
12 Replies

6. UNIX for Dummies Questions & Answers

prepare a perl tuts

Hi I am working on perl for last 3 yrs and as part of knowledge sharing i have been told to conduct sessions with other teams.Only 1 session with basic details. My problem is i am not sure what all should i cover in this tut ? because i learned perl on my own. so i am not sure where to start... (4 Replies)
Discussion started by: zedex
4 Replies

7. Shell Programming and Scripting

How can i prepare a file by comparing two other files?

File 1 data: TestA TestB TestC File 2 data: TestA TestD TestE My Output File (pick all from both and create a file without duplicate data) ---------------------------------------------------------------------- TestA TestB TestC (3 Replies)
Discussion started by: manmohanpv
3 Replies

8. UNIX for Dummies Questions & Answers

How to prepare HDD for Installation of Solaris

Hi All, I need some advice on dual booting a dell box so that I can have WinXP and Solaris 10 OS there. The question is, what is the best way of preparing the hdd for prior to installation? I have used created two partition, one for xp and the and the other unallocated partition for Solaris.... (3 Replies)
Discussion started by: S0laris_B0y
3 Replies
Login or Register to Ask a Question