a.logファイルから特定の文字列だけ取得して新ファイルに出力させたいです。
a.logファイルの中身
<123>2018-08-01T08:59:59Z ct6149 log[999999]: 11.222.333.333 "-" "-" [01/2018:08:59:59 +0000] "GET /photo/9999.jpg HTTP/1.1" 200 157305 1234 "https://www.you.net/03?t&pa=1" "Mozilla/1.0 (Win NT 10.0; AAA99; Trident/7.0; rv:11.0) like Goooo" <123>2018-08-01T08:59:59Z ch1722 log[885560]: 33.444.555.666 "-" "-" [01/2018:08:59:59 +0000] "GET /css/main.css HTTP/1.1" 304 "-" 127 "https://www.you.net/89999?t.snu.t" "Mozilla/2.0 (iPhone; CPU iPhone OS 99_9_9 like Mac OS X) AppleWebKit/999.9.99 (KHTML, like Gecko) Version/11.0 Mobile/99M999 Safari/600.1" <123>2018-08-01T09:00:00Z cd1878 log[121131]: 44.555.666.777 "-" "-" [01/2018:09:00:00 +0000] "GET /images/0001.jpg HTTP/1.1" 200 79906 1206 "https://www.you.net/L?&pa=4" "Mozilla/3.0 (Win NT 9.1; Trident/7.0; rv:99.0) like Gooo" <134>2018-08-01T09:04:28Z ct6666 log[222221]: 77.888.999.000 "-" "-" [01/2018:09:04:28 +0000] "POST /api/lan HTTP/1.1" 200 28 38571 "https://www.you.net/stay" "Mozilla/5.0 (Windows NT 6.3; WOW64; Trident/7.0; Touch; rv:11.0) like Gooo" ・ ・ 上記のような内容が1000行以上続く。。。
上記を下記のように、出力しなおしたい。
(GETからURLまでに出力し直したい。)
file
1"GET /photo/9999.jpg HTTP/1.1" 200 157305 1234 "https://www.you.net/03?t&pa=1" 2"GET /css/main.css HTTP/1.1" 304 "-" 127 "https://www.you.net/89999?t.snu.t" 3"GET /images/0001.jpg HTTP/1.1" 200 79906 1206 "https://www.you.net/L?&pa=4" 4"POST /api/lan HTTP/1.1" 200 28 38571 "https://www.you.net/stay" 5 ・ 6 ・
以下、かきかけのコードです。
python
1path = "/div/a.log" 2 3# 行の出力 4with open(path) as f: 5 lines = f.readlines() 6 7lines_strip = [line.strip() for line in lines] 8 9for lines in lines_strip: 10 print(lines)
###参考URL
Pythonでファイル内の任意の文字列を含む行を抽出(grep的処理)
Pythonでgrepやawkのような行の抽出を行う
Pythonで文字列を分割
すみませんが、よろしくお願い致します。

回答4件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/08/10 00:38