parsing log files in to a spread sheet


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting parsing log files in to a spread sheet
# 15  
Old 10-19-2012
Code:
$ awk -F'[][,="]' -v qq='"' -f remo.awk testlogs.txt
16/Oct/2012:13:12:55,E432834, Invalid credentials ,ag-agsos123-myss-dev2
15/Oct/2012:10:56:48,e420839,Invalid password format,ag-agsosg84-wid2-dev1
18/Oct/2012:04:49:25,shayne, Invalid credentials ,ag-wwsosg02-csj-dev1
11/Feb/2011:03:42:21,p468126, Invalid credentials - null password ,ag-wwsosg02-ds-dev1
11/Feb/2011:10:20:18,p457653, Invalid credentials ,ag-wwsosg02-rds-dev1
11/Feb/2011:10:09:09,p105666, Invalid credentials ,ag-agsos123-myss-dev2
07/Feb/2011:17:47:26,e420858, Invalid credentials ,ag-wwsosg02-rds-dev1

looks fine to me given your sample file....
Do you have any empty lines in your REAL file?
I've noticed you attached testlogs.txt, but ran your script against testlogs1 file. Same files?
To make the script a bit more bullet proof:
Code:
BEGIN {
  OFS=","
}
NF>=5{
  reason=$(NF-5)
  if (reason ~ /^[0-9][0-9]*/)
     reason=$(NF-4)

  match($0, "[^" qq "]* GET")
  agent=substr($0,RSTART, RLENGTH-4)

  print substr($2,1,index($2," ")-1),$5, reason,agent
}

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Save log data in excel sheet

Hello, I have the following data format in a log file : a : x1 b : x2 c : x3 d : x4 -------- a : x5 b : x6 c : x7 d : x8 so the same fields ( a ,b ,c,d) repeated many times in the same log file but with different "x" values (x5,x6,x7,x8). I need a script to save this data in an... (6 Replies)
Discussion started by: mm00123
6 Replies

2. Shell Programming and Scripting

Attaching two text files in two different sheet in same excel

Hi, My requirement is to get attach two different text file contents to two different sheets in same excelsheet. Also, is there any way we can name the tabs as desired ? Kindly assist. (2 Replies)
Discussion started by: sanjaydubey2006
2 Replies

3. Programming

Need an c,c++,or java code for parsing the log files

need the code for c,c++,java for parsing the log file (5 Replies)
Discussion started by: raghuraipur
5 Replies

4. UNIX for Dummies Questions & Answers

how to fill the name of the spread sheet as a cell's data

In open office spreadsheet, i would like to fill a cell with the name of the spread sheet. That is if the file name of spread sheet is, team.ods, then i have to fill a specific cell with that name 'team'. How to do that ? I have more spread sheets to be created, so i want it to be done... (0 Replies)
Discussion started by: thegeek
0 Replies

5. Shell Programming and Scripting

parsing log files, removing spaces and replace with commas

Hello all i am working on a database to import log files from my systems, but i cannot seem to find the answer. I searched here for a good bit and couldnt peice together what i was looking for. I know you could do this with awk, i just dont know how. Any help would be greatly appreciated.... (6 Replies)
Discussion started by: caddyjoe77
6 Replies

6. Shell Programming and Scripting

Parsing log files, displaying logs between specific dates

Sorry, couldn't really think of a simple subject/title. So, I have a log file, and the dates are displayed like so: 2009-03-05 02:49:44 So the first and second field are the date/time. I can change them into a unix timestamp easily with: date -d "2009-03-05 02:49:44" +%s However,... (17 Replies)
Discussion started by: Rhije
17 Replies

7. Shell Programming and Scripting

Help needed to combine files to excel sheet

Hi, I have several hundreds of text files which I would like to combine them onto excel sheet. Does anyone know how to combine them into different excel sheet in one workbook using Bash script? Please advise. THanks. I forgot to mention my file is something like below:- A B ... (5 Replies)
Discussion started by: ahjiefreak
5 Replies

8. UNIX for Dummies Questions & Answers

How can import data files to XL sheet.

Hi, I have the file(F1.XL) in Unix Box. it's updating every 1hr. I would like to import f1.xl to Windows excel sheet, when i need see the reports. can any one clarify, is there any VB script for importing data from UNIX, like sql connection.... thanks (1 Reply)
Discussion started by: koti_rama
1 Replies

9. Programming

spawning multiple processes spread across two files

I want to spawn n child processes but have two different classes..with the foremost one forking/spawning the child process and the latter performing a function w/ the spawned processes. I can do this in one class with an if statement and the simple if((pid=fork())==0) //child process { ... (1 Reply)
Discussion started by: StrengthThaDon
1 Replies

10. UNIX for Advanced & Expert Users

Exporting files from unix to Excel sheet

How can we export a file in unix with certain number of columns to an excel sheet. It's very useful in time saving...... (3 Replies)
Discussion started by: bishweshwar
3 Replies
Login or Register to Ask a Question