Han-Gang / test

test
0 stars 0 forks source link

python解析日志 处理 1, 2, 3, "kljalsdf , sdf, asdf \" fasdf \"", 0, 0这样的格式 #4

Open Han-Gang opened 5 years ago

Han-Gang commented 5 years ago

python解析日志 处理 1, 2, 3, "kljalsdf , sdf, asdf \" fasdf \"", 0, 0这样的格式 要首先把 , " 全部替换为," (逗号和双引号之间无空格) 然后


with open('XXXXX.log.1', 'rU') as f:
  reader = csv.reader(f, delimiter=',',doublequote=True, escapechar='\\')
  for i in reader:
    for j in i:
      print j
Han-Gang commented 5 years ago

shlex
https://cloud.tencent.com/developer/section/1367963

Han-Gang commented 5 years ago

grep -oP '"(\"|[^"]){10,}(?!\")"' test

python -c 'import urllib;print urllib.quote("\xxx\xxx\xxx")'

Han-Gang commented 5 years ago

doublequote 是 "" 替换 为"

Han-Gang commented 5 years ago
import sys
import urllib
for line in sys.stdin:
  cmd = 'print '+line
  exec(cmd)
Han-Gang commented 5 years ago

import sys import urllib for line in sys.stdin: cmd = 'print '+line.strip() + " + ';'" exec(cmd)

Han-Gang commented 5 years ago
import csv
out = open ('output.txt','w')

with open('XXX.log', 'rU') as f:
        reader = csv.reader(f, delimiter="\t")
        for i in reader:
                print i[2],i[17]
                out.write(i[2]+"\n")

out.close()