CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Parsing Log Lines

 



Amrit
Novice

Dec 23, 2011, 1:14 AM

Post #1 of 2 (775 views)
Parsing Log Lines Can't Post

Dec 23 00:42:31 h d/d/3. [p] 1 I d/d/1 [2] query=
[SELECT
pool.LINE AS LINE,
pool.ID AS LOCATION_ID,
FROM
PROD pool WHERE
SD IN ('N')] (e.execute)
Dec 23 00:42:30 acccc da/d/3 [-4\066ead-1] 626 fo k/dl.0 [29] Debug d/3/0 get a connection... (com.getConnection)
Dec 23 00:42:30 h d/d/3 [p]628 Info java/db/3.1 con com. from the connection pool - id: com. - settings: commit=true,transaction isolation=2 (<LPP)
Dec 23 00:42:30 h d/d/3. [p] 1 D dat/3/1 [2] qs= (com.msdw.d)
Dec 23 00:42:30 h d/d/3.0 [p]
Dec 23 00:42:30 h d/3.0 [p] 1D d/3/1.0 [9] resultSet=
Set =
--
Dec 23 00:42:31 h d/d/3. [p] 1 I d/d/1 [2] query=
[SELECT
pool.LINE AS LINE,
pool.ID AS LOCATION_ID,
FROM
PROD pool WHERE
SD IN ('N')] (e.execute)


I want to grep only the query and print in another file on Unix using Perl Script.

query=[SELECT pool.Line AS LINE,pool.ID AS LOCATION_ID,pool.CODE AS CODE,pool.REVERSE AS REVERSE,pool.REPO AS POOL_RTE_REPO,pool.DATE_YYYYMMDD AS DATE_YYYYMMDD,pool.DATE_YYYYMMDD_C AS DATE_YYYYMMDD_C FROM PROD pool WHERE SD I ('N')] .execute)


Any help is greatly Appreciated Smile


rovf
Veteran

Dec 23, 2011, 5:29 AM

Post #2 of 2 (766 views)
Re: [Amrit] Parsing Log Lines [In reply to] Can't Post

There are several approaches to this problem, but it depends on what else (besides the queries) can be in a log file. You have posted examples, but of course I don't know to what extend theses examples are complete.

Here is the outline to one possible solution:

Assuming that you read the logfile line by line, you can check for lines starting with a timestamp and ending in the string "query=". You then know that the following lines, up to the one ending in the string "(e.execute)", make up one query, i.e. you collect those lines and write them to a file.

You can code this simply like in any other programming language, using if (....) to test the lines.

Perl offers you, however, another way to do it, which is not found in most other languages: The .. (double-dot) operator. Have a look at the "perlop" page (type "perldoc perlop" on the command line) and read the section about "Range Operators". It contains examples which are similar to what you are looking for.

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives