英文:
How can I extract the gif files requested by a GET request with Http response 200 from a log?
问题
livevideo.gif
count.gif
NASA-logo.gif
KSC-logosmall.gif
英文:
I have the next log file and I need to extract the gif files which were requested by a GET request and its status was 200.
unicomp6.unicomp.net ‐ ‐ [01/Jul/1995:00:00:06 ‐0400] "GET /shuttle/countdown/ HTTP/1.0" 200 3985
burger.letters.com ‐ ‐ [01/Jul/1995:00:00:11 ‐0400] "GET /shuttle/countdown/liftoff.html HTTP/1.0" 304 0
burger.letters.com ‐ ‐ [01/Jul/1995:00:00:12 ‐0400] "GET /images/NASA‐logosmall.gif HTTP/1.0" 304 0
burger.letters.com ‐ ‐ [01/Jul/1995:00:00:12 ‐0400] "GET/shuttle/countdown/video/livevideo.gif HTTP/1.0" 200 0
d104.aa.net ‐ ‐ [01/Jul/1995:00:00:13 ‐0400] "GET /shuttle/countdown/HTTP/1.0" 200 3985
unicomp6.unicomp.net ‐ ‐ [01/Jul/1995:00:00:14 ‐0400] "GET/shuttle/countdown/count.gif HTTP/1.0" 200 40310
unicomp6.unicomp.net ‐ ‐ [01/Jul/1995:00:00:14 ‐0400] "GET /images/NASA‐logosmall.gif HTTP/1.0" 200 786
unicomp6.unicomp.net ‐ ‐ [01/Jul/1995:00:00:14 ‐0400] "GET /images/KSC‐logosmall.gif HTTP/1.0" 200 1204
d104.aa.net ‐ ‐ [01/Jul/1995:00:00:15 ‐0400] "GET/shuttle/countdown/count.gif HTTP/1.0" 200 40310
d104.aa.net ‐ ‐ [01/Jul/1995:00:00:15 ‐0400] "GET /images/NASA‐logosmall.gif HTTP/1.0" 200 786
From the above example the response must be:
livevideo.gif
count.gif
NASA-logo.gif
KSC-logosmall.gif
As you can see in the response there are not duplicates, for example in the row 6 we have the count.gif record requested by a Get and with status 200, the same happens in the row 9 and in the response we have only one count.gif record.
答案1
得分: 0
尝试逐行读取文件,从每一行中提取文件名。这里可以使用正则表达式。
将gif文件名存储在一个Set
中,以自动消除重复项。
英文:
Try reading the file one line at a time to extract the file name from each line. A regular expression would be useful here.
Store the gif file names in a Set
to automatically eliminate the duplicates.
专注分享java语言的经验与见解,让所有开发者获益!
评论