473,396 Members | 1,998 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Print all entries with status codes in the 200's

can anyone tell me how to print out the ip address and timestamp from a weblog file for all the entries where the status code begins with 2.
Mar 10 '15 #1
5 1355
bvdet
2,851 Expert Mod 2GB
Are you able to read the file? What is the structure of the file?
Mar 10 '15 #2
sorry i should have said its an apache server log file
Mar 10 '15 #3
bvdet
2,851 Expert Mod 2GB
Let me repeat my questions. Are you able to read the file? What is the structure of the file (provide a sample)?
Mar 10 '15 #4
its combined log format -

127.0.0.1 - frank [10/Oct/2000:13:55:36 -0700] "GET /apache_pb.gif HTTP/1.0" 200 2326 "http://www.example.com/start.html" "Mozilla/4.08 [en] (Win98; I ;Nav)"
Mar 10 '15 #5
bvdet
2,851 Expert Mod 2GB
The information can be parsed from the given line of text like this:
Expand|Select|Wrap|Line Numbers
  1. >>> s = '127.0.0.1 - frank [10/Oct/2000:13:55:36 -0700] "GET /apache_pb.gif HTTP/1.0" 200 2326 "http://www.example.com/start.html" "Mozilla/4.08 [en] (Win98; I ;Nav)"'
  2. >>> ip = s.split("-")[0].strip()
  3. >>> ip
  4. '127.0.0.1'
  5. >>> timestamp = s[s.index("[")+1:s.index("]")]
  6. >>> timestamp
  7. '10/Oct/2000:13:55:36 -0700'
  8. >>> 
Mar 10 '15 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: Gianni Mariani | last post by:
I'm involved in a new project and a new member on the team has voiced a strong opinion that we should utilize exceptions. The other members on the team indicate that they have either been burned...
1
by: chris fink | last post by:
Hi, What are the appropriate HTTP Status Codes for the following: 1. XML is not well-formed (structure problem).... 2. XML is not valid (as per DTD/XSD/XDR).....missing req'd field, etc I...
2
by: bwmiller16 | last post by:
Anyone - Can anybody tell me where I would find the linux status codes for such udb utilities as backup, etc.? For instance, in my cron job I have: db2 backup database $dir to $BACKUP_DIR...
6
by: Andy Fish | last post by:
Hi, I've RTFM'd in vain for some named constants in the asp.net framework representing the HTTP error codes - the equivalent of Java's HttpServletResponse.SC_NOT_FOUND for 404 etc. All the...
0
by: Daniel Kopp | last post by:
Hi! I tried to implement custom error pages using the <customErrors> directive in a web.config file. It worked fine for "simple" errors like HTTP 404, like this example: <customErrors...
1
by: chen | last post by:
We're having an internal debate about the merits & demerits of returning status codes in the output message vs exceptions to signify errors in handling a Web method. The status code camp is...
0
by: Alvin A. Delagon | last post by:
I'm writing a simple python code that will upload files onto a ftp server. Everything's fine and working great except that the script I wrote don't know is an upload is successful or not. Is there...
1
by: Alvin A. Delagon | last post by:
Greetings! Is there any way I can obtain the HTTP status codes when using the urllib module? As of now I can only think of doing a regex on the result of the read(). Thanks in advance! ^_^
2
by: JThomas | last post by:
Hello! I'm having trouble with a page apparently causing my client's Safari browser to time out. I don't actually have access to a Mac & Safari, and haven't been able to physically see this...
3
by: chjiangwh | last post by:
hello,everybody I want to print extended ASCII codes in a windows console app. I want to print the chessboard in the console screen,using printf("%c",219) but it appears strange code. Anybody...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.