从CSV中删除双引号,Splunk REST输出

时间:2018-12-20 19:09:45

标签: python csv splunk

我正在尝试从CSV中删除所有双引号。

CSV当前由Splunk的HTTP REST API生成(我知道有一个python SDK,但这是我现在所在的位置)

我还有另一个吸收该CSV的Java脚本,尽管未编码为处理引号。

我想去除引号,以便输出类似于: 9230230283,RDFO890

while (isDone != 1):
  p = subprocess.Popen(["curl", "-k", "-u", "user:pass", ep], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
  out,err = p.communicate()
  tree = etree.parse(StringIO(out))
  isDone = int(tree.xpath('//*[@name="isDone"]/text()').pop())

  if isDone == 1:
    p = subprocess.Popen(["curl", "-k", "-u", "user:pass",     ep+"/results", "-d", "output_mode=csv", "--get"], stdout=subprocess.PIPE,    stderr=subprocess.PIPE)
   out,err = p.communicate()
   print out

产生:

"A1790719C","484431004"
"B8653D513","287900102"
"213B6BA33","225763409"
"1B9A776C","38708902"

我尝试做:

out,err = p.communicate()
reader = csv.reader(out, quoting=csv.QUOTE_NONE)  # <_csv.reader object at 0x10956e0>
for row in reader:
    print(row)

但是它只会产生:

['F']
['0']
['5']
['9']
['D']
['2']
['6']
['8']
['1']
['F']
['E']
['"']
['', '']
['"']
['.']
['0']
['0']
['3']
[':']
['4']
['6']
['5']
['6']
['0']
['3']
['4']
['0']
['8']
['"']
[]
['"']
['6']
['5']
['F']
['8']
['B']

0 个答案:

没有答案